diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 11:45:20 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 11:45:20 +0300 |
commit | 3cb9f16bb195a3d004692e85e7f9190a9469fcb1 (patch) | |
tree | f82ea305b818d0af77cd0e28dd2c3c470985d6ee /array.c | |
parent | 1be20bcb0e717e35a6de5074223252f2eb1c5aa5 (diff) | |
parent | 906ac1a525dd0f7ad87bafdaf882323938842760 (diff) | |
download | egawk-3cb9f16bb195a3d004692e85e7f9190a9469fcb1.tar.gz egawk-3cb9f16bb195a3d004692e85e7f9190a9469fcb1.tar.bz2 egawk-3cb9f16bb195a3d004692e85e7f9190a9469fcb1.zip |
Merge branch 'master' into feature/fix-comments
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -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; } |