diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 11:45:05 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 11:45:05 +0300 |
commit | 4b68f4ebe7381644e5652a88a5104a10f10f66a7 (patch) | |
tree | e242d76e4f41cd63466cf044edcc5868b810ccda /array.c | |
parent | bb25148a8e3c8d953f632eb635669abaccedc9a4 (diff) | |
parent | 906ac1a525dd0f7ad87bafdaf882323938842760 (diff) | |
download | egawk-4b68f4ebe7381644e5652a88a5104a10f10f66a7.tar.gz egawk-4b68f4ebe7381644e5652a88a5104a10f10f66a7.tar.bz2 egawk-4b68f4ebe7381644e5652a88a5104a10f10f66a7.zip |
Merge branch 'master' into feature/api-mpfr
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; } |