From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 54BBA384400F for ; Mon, 19 Oct 2020 16:05:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 54BBA384400F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sebastian.huber@embedded-brains.de Received: from sslproxy02.your-server.de ([78.47.166.47]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1kUXf1-0004OZ-By for newlib@sourceware.org; Mon, 19 Oct 2020 18:05:23 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1kUXf1-0002l9-90 for newlib@sourceware.org; Mon, 19 Oct 2020 18:05:23 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id E99C02A1686 for ; Mon, 19 Oct 2020 18:04:10 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id i2wQDDdyvzU5 for ; Mon, 19 Oct 2020 18:04:10 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 7BE482A165B for ; Mon, 19 Oct 2020 18:04:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XQ8rnRIFd_h0 for ; Mon, 19 Oct 2020 18:04:10 +0200 (CEST) Received: from linux-diu0.suse (unknown [192.168.96.161]) by mail.embedded-brains.de (Postfix) with ESMTP id 5754F2A1682 for ; Mon, 19 Oct 2020 18:04:10 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 03/11] For the case when RB_REMOVE requires a nontrivial Date: Mon, 19 Oct 2020 18:05:16 +0200 Message-Id: <20201019160522.15408-4-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201019160522.15408-1-sebastian.huber@embedded-brains.de> References: <20201019160522.15408-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.102.4/25962/Mon Oct 19 15:57:02 2020) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2020 16:05:25 -0000 From: dougm search to find the node to replace the one being removed, restructure to = first remove the replacement node and correct the parent pointers around it, an= d then let the all-cases code at the end deal with the parent of the deleted nod= e, making it point to the replacement node. This removes one or two conditio= nal branches. Reviewed by: markj Tested by: pho Differential Revision: https://reviews.freebsd.org/D24845 --- newlib/libc/include/sys/tree.h | 52 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/newlib/libc/include/sys/tree.h b/newlib/libc/include/sys/tre= e.h index 5c31ff2ea..b1e5e23a7 100644 --- a/newlib/libc/include/sys/tree.h +++ b/newlib/libc/include/sys/tree.h @@ -562,48 +562,44 @@ name##_RB_REMOVE_COLOR(struct name *head, struct ty= pe *parent, struct type *elm) attr struct type * \ name##_RB_REMOVE(struct name *head, struct type *elm) \ { \ - struct type *child, *parent, *old =3D elm; \ + struct type *child, *parent, *parent_old, *old =3D elm; \ int color; \ - if (RB_LEFT(elm, field) =3D=3D NULL) \ - child =3D RB_RIGHT(elm, field); \ - else if (RB_RIGHT(elm, field) =3D=3D NULL) \ - child =3D RB_LEFT(elm, field); \ - else { \ + parent_old =3D parent =3D RB_PARENT(elm, field); \ + color =3D RB_COLOR(elm, field); \ + if (RB_LEFT(elm, field) =3D=3D NULL) { \ + elm =3D child =3D RB_RIGHT(elm, field); \ + if (elm !=3D NULL) \ + RB_PARENT(elm, field) =3D parent; \ + } else if (RB_RIGHT(elm, field) =3D=3D NULL) { \ + elm =3D child =3D RB_LEFT(elm, field); \ + RB_PARENT(elm, field) =3D parent; \ + } else { \ elm =3D RB_RIGHT(old, field); \ if ((child =3D RB_LEFT(elm, field)) =3D=3D NULL) { \ child =3D RB_RIGHT(elm, field); \ RB_RIGHT(old, field) =3D child; \ - RB_PARENT(elm, field) =3D elm; \ + parent =3D elm; \ } else { \ do \ elm =3D child; \ while ((child =3D RB_LEFT(elm, field)) !=3D NULL); \ child =3D RB_RIGHT(elm, field); \ + parent =3D RB_PARENT(elm, field); \ + RB_LEFT(parent, field) =3D child; \ + if (child !=3D NULL) \ + RB_PARENT(child, field) =3D parent; \ RB_PARENT(RB_RIGHT(old, field), field) =3D elm; \ } \ RB_PARENT(RB_LEFT(old, field), field) =3D elm; \ - parent =3D RB_PARENT(old, field); \ - if (parent !=3D NULL) { \ - if (RB_LEFT(parent, field) =3D=3D old) \ - RB_LEFT(parent, field) =3D elm; \ - else \ - RB_RIGHT(parent, field) =3D elm; \ - } else \ - RB_ROOT(head) =3D elm; \ + color =3D RB_COLOR(elm, field); \ + elm->field =3D old->field; \ } \ - parent =3D RB_PARENT(elm, field); \ - color =3D RB_COLOR(elm, field); \ - if (child !=3D NULL) \ - RB_PARENT(child, field) =3D parent; \ - if (parent !=3D NULL) { \ - if (RB_LEFT(parent, field) =3D=3D elm) \ - RB_LEFT(parent, field) =3D child; \ - else \ - RB_RIGHT(parent, field) =3D child; \ - } else \ - RB_ROOT(head) =3D child; \ - if (elm !=3D old) \ - (elm)->field =3D (old)->field; \ + if (parent_old =3D=3D NULL) \ + RB_ROOT(head) =3D elm; \ + else if (RB_LEFT(parent_old, field) =3D=3D old) \ + RB_LEFT(parent_old, field) =3D elm; \ + else \ + RB_RIGHT(parent_old, field) =3D elm; \ if (color =3D=3D RB_BLACK) \ name##_RB_REMOVE_COLOR(head, parent, child); \ while (parent !=3D NULL) { \ --=20 2.26.2