apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1664447 - /apr/apr/trunk/tables/apr_skiplist.c
Date Thu, 05 Mar 2015 18:31:45 GMT
Author: ylavic
Date: Thu Mar  5 18:31:45 2015
New Revision: 1664447

URL: http://svn.apache.org/r1664447
Log:
skiplist: Follow up to r1664406: use insert() in apr_skiplist_merge and optimize test in insert_compare().

Modified:
    apr/apr/trunk/tables/apr_skiplist.c

Modified: apr/apr/trunk/tables/apr_skiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_skiplist.c?rev=1664447&r1=1664446&r2=1664447&view=diff
==============================================================================
--- apr/apr/trunk/tables/apr_skiplist.c (original)
+++ apr/apr/trunk/tables/apr_skiplist.c Thu Mar  5 18:31:45 2015
@@ -418,16 +418,18 @@ static apr_skiplistnode *insert_compare(
      */
     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
         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);



Mime
View raw message