aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-04-12 11:45:44 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-04-12 11:45:44 +0300
commit8f83ab76a1d8861d9a992290f2691443d5169c89 (patch)
treeab97e5c6532b812c681121127694d6ece4a2e92d /array.c
parent6ba1d42808efba4f381aaeec54211a7802b816ff (diff)
parent906ac1a525dd0f7ad87bafdaf882323938842760 (diff)
downloadegawk-8f83ab76a1d8861d9a992290f2691443d5169c89.tar.gz
egawk-8f83ab76a1d8861d9a992290f2691443d5169c89.tar.bz2
egawk-8f83ab76a1d8861d9a992290f2691443d5169c89.zip
Merge branch 'master' into feature/stringfix
Diffstat (limited to 'array.c')
-rw-r--r--array.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/array.c b/array.c
index cee1c729..3159bfdc 100644
--- a/array.c
+++ b/array.c
@@ -1353,12 +1353,22 @@ assoc_list(NODE *symbol, const char *sort_str, sort_context_t sort_ctxt)
list = symbol->alist(symbol, & akind);
assoc_kind = (assoc_kind_t) akind.flags; /* symbol->alist can modify it */
- if (list == NULL || ! cmp_func || (assoc_kind & (AASC|ADESC)) != 0)
- return list; /* empty list or unsorted, or list already sorted */
+ /* check for empty list or unsorted, or list already sorted */
+ if (list != NULL && cmp_func != NULL && (assoc_kind & (AASC|ADESC)) == 0) {
+ num_elems = assoc_length(symbol);
- num_elems = assoc_length(symbol);
+ qsort(list, num_elems, elem_size * sizeof(NODE *), cmp_func); /* shazzam! */
- qsort(list, num_elems, elem_size * sizeof(NODE *), cmp_func); /* shazzam! */
+ if (sort_ctxt == SORTED_IN && (assoc_kind & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) {
+ /* relocate all index nodes to the first half of the list. */
+ for (j = 1; j < num_elems; j++)
+ list[j] = list[2 * j];
+
+ /* give back extra memory */
+
+ erealloc(list, NODE **, num_elems * sizeof(NODE *), "assoc_list");
+ }
+ }
if (cmp_func == sort_user_func) {
code = POP_CODE();
@@ -1367,15 +1377,5 @@ assoc_list(NODE *symbol, const char *sort_str, sort_context_t sort_ctxt)
bcfree(code); /* Op_func_call */
}
- if (sort_ctxt == SORTED_IN && (assoc_kind & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) {
- /* relocate all index nodes to the first half of the list. */
- for (j = 1; j < num_elems; j++)
- list[j] = list[2 * j];
-
- /* give back extra memory */
-
- erealloc(list, NODE **, num_elems * sizeof(NODE *), "assoc_list");
- }
-
return list;
}