diff options
author | ylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68> | 2015-03-05 18:31:45 +0000 |
---|---|---|
committer | ylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68> | 2015-03-05 18:31:45 +0000 |
commit | a0929637a49aea5c6abaa6b0b327984dfe52a093 (patch) | |
tree | b4b525f550c62986b4bca3f2c489bf84742a95b0 /tables | |
parent | ac3468e6492757aa12cabc3ec553bac486a2d59a (diff) | |
download | libapr-a0929637a49aea5c6abaa6b0b327984dfe52a093.tar.gz |
skiplist: Follow up to r1664406: use insert() in apr_skiplist_merge and optimize test in insert_compare().
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1664447 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r-- | tables/apr_skiplist.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tables/apr_skiplist.c b/tables/apr_skiplist.c index 25a6ad662..e691b97e1 100644 --- a/tables/apr_skiplist.c +++ b/tables/apr_skiplist.c @@ -418,16 +418,18 @@ static apr_skiplistnode *insert_compare(apr_skiplist *sl, void *data, */ m = sl->top; while (m) { - int compared = -1; - if (m->next) { - compared = comp(data, m->next->data); - } + int compared; + compared = (m->next) ? comp(data, m->next->data) : -1; if (compared == 0 && !add) { /* Keep the existing element(s) */ skiplist_stack_clear(sl); return NULL; } - if (compared < 0 || ((compared <= 0) && add)) { + /* + * To maintain stability, dups must be added AFTER each + * other. + */ + if (compared <= 0) { if (ch <= nh) { /* push on stack */ skiplist_stack_push(sl, m); @@ -728,10 +730,10 @@ APR_DECLARE(apr_skiplist *) apr_skiplist_merge(apr_skiplist *sl1, apr_skiplist * apr_skiplist_remove_all(sl2, NULL); return sl1; } - /* This is what makes it brute force... Just add :/ */ + /* This is what makes it brute force... Just insert :/ */ b2 = apr_skiplist_getlist(sl2); while (b2) { - apr_skiplist_add(sl1, b2->data); + apr_skiplist_insert(sl1, b2->data); apr_skiplist_next(sl2, &b2); } apr_skiplist_remove_all(sl2, NULL); |