Return-Path: X-Original-To: apmail-apr-commits-archive@www.apache.org Delivered-To: apmail-apr-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A9F9B10191 for ; Thu, 5 Mar 2015 18:31:55 +0000 (UTC) Received: (qmail 30561 invoked by uid 500); 5 Mar 2015 18:31:46 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 30510 invoked by uid 500); 5 Mar 2015 18:31:46 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 30501 invoked by uid 99); 5 Mar 2015 18:31:46 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Mar 2015 18:31:46 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id F0A3BAC03BB for ; Thu, 5 Mar 2015 18:31:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1664447 - /apr/apr/trunk/tables/apr_skiplist.c Date: Thu, 05 Mar 2015 18:31:45 -0000 To: commits@apr.apache.org From: ylavic@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150305183145.F0A3BAC03BB@hades.apache.org> 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);