Index: tools/jam/src/lists.c =================================================================== --- tools/jam/src/lists.c (revision 44041) +++ tools/jam/src/lists.c (working copy) @@ -133,82 +133,42 @@ return nl; } +static int str_ptr_compare(const void *va, const void *vb) +{ + char* a = *( (char**)va ); + char* b = *( (char**)vb ); + return strcmp(b, a); +} + LIST * list_sort( LIST *l) { + int len, ii; + char** strings; + LIST* listp; + LIST* result = 0; - LIST* first = 0; - LIST* second = 0; - LIST* merged = l; - LIST* result; - if (!l) return L0; - for(;;) { - - /* Split the list in two */ - LIST** dst = &first; - LIST* src = merged; - - for(;;) { - - *dst = list_append(*dst, list_new(0, src->string)); - - if (!src->next) - break; + len = list_length(l); + strings = (char**)BJAM_MALLOC( len * sizeof(char*) ); - if (strcmp(src->string, src->next->string) > 0) - { - if (dst == &first) - dst = &second; - else - dst = &first; - } - - src = src->next; - } + listp = l; + for (ii = 0; ii < len; ++ii) { + strings[ii] = listp->string; + listp = listp->next; + } - if (merged != l) - list_free( merged ); - merged = 0; - - if (second == 0) { - result = first; - break; - } + qsort(strings, len, sizeof(char*), str_ptr_compare); - - /* Merge lists 'first' and 'second' into 'merged' and free - 'first'/'second'. */ - { - LIST* f = first; - LIST* s = second; - - while(f && s) - { - if (strcmp(f->string, s->string) < 0) - { - merged = list_append( merged, list_new(0, f->string )); - f = f->next; - } - else - { - merged = list_append( merged, list_new(0, s->string )); - s = s->next; - } - } - - merged = list_copy( merged, f ); - merged = list_copy( merged, s ); - list_free( first ); - list_free( second ); - first = 0; - second = 0; - } + for (ii = 0; ii < len; ++ii) { + result = list_append( result, list_new(0, strings[ii]) ); } + BJAM_FREE(strings); + return result; }