summaryrefslogtreecommitdiff
path: root/tables
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2015-03-05 18:31:45 +0000
committerYann Ylavic <ylavic@apache.org>2015-03-05 18:31:45 +0000
commit49f94ab2b143f8856011cd3b56ecd46316cbec20 (patch)
treeb4b525f550c62986b4bca3f2c489bf84742a95b0 /tables
parent5df758efcd183994266240c912df894cdcc38637 (diff)
downloadapr-49f94ab2b143f8856011cd3b56ecd46316cbec20.tar.gz
skiplist: Follow up to r1664406: use insert() in apr_skiplist_merge and optimize test in insert_compare().
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1664447 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r--tables/apr_skiplist.c16
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);