From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by sourceware.org (Postfix) with ESMTPS id D1BEC3858D32 for ; Mon, 17 Oct 2022 14:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D1BEC3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.org Received: (Authenticated sender: dodji@seketeli.org) by mail.gandi.net (Postfix) with ESMTPSA id 54B6D10000D; Mon, 17 Oct 2022 14:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seketeli.org; s=gm1; t=1666016077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M6nVmnwOBs0Bq+Cae07EJ5LhtKsjIqztBCbLSORJ394=; b=Ra6eBeVnN6/O+XbEOTVDTHoxFlzJBjk+WZVgHRpPkRnHoMs802CURGPQHEBIhCZ7Os5aSy IhPMexhVQh6Yxe5I+9gPWa2/XEvvcvtLvfl6mQABbnZZrsXTNkoHaKxrLE/R5fak6EJvDd 2vNPWWCrgooAsv9eAAaZlx/ahxl2V6T95vM+mrEEtekkOHTmUMJ0Eko3NsteG7Mpo6ggF/ q4DGdBk8DDPezBIYZCJYMueiIRzap1H6uGzx6+KbfCx5z39EbSfZsNzvflVtir9awSalin JNPO100wsK10whj5RAVdTgO8gxV05cUpk7Os1p99Ss2sEZJeYWHJ6z8TJ2tYsA== Received: by localhost (Postfix, from userid 1000) id EBB80581C53; Mon, 17 Oct 2022 16:14:35 +0200 (CEST) From: Dodji Seketeli To: Xiaole He via Libabigail Cc: Xiaole He , Xiaole He Subject: Re: [PATCH] abg-reader: optimize if construction Organization: Me, myself and I References: <20221016064703.67180-1-hexiaole1994@126.com> X-Operating-System: Fedora 38 X-URL: http://www.seketeli.net/~dodji Date: Mon, 17 Oct 2022 16:14:35 +0200 In-Reply-To: <20221016064703.67180-1-hexiaole1994@126.com> (Xiaole He via Libabigail's message of "Sun, 16 Oct 2022 06:47:03 +0000") Message-ID: <87leper0z8.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Xiaole, Xiaole He via Libabigail a =C3=A9crit: > In 'build_enum_type_decl' function of 'src/abg-reader.cc', the > 'for loop' walk through all the child nodes of the '' for > seeking '' and '': > > /* original src/abg-reader.cc begin */ > static enum_type_decl_sptr > build_enum_type_decl(read_context& ctxt, > const xmlNodePtr node, > bool add_to_current_scope) > { > ... > for (xmlNodePtr n =3D xmlFirstElementChild(node); > n; > n =3D xmlNextElementSibling(n)) > { > if (xmlStrEqual(n->name, BAD_CAST("underlying-type"))) > { > ... > } > > if (xmlStrEqual(n->name, BAD_CAST("enumerator"))) > { > ... > } > } > ... > } > /* original src/abg-reader.cc end */ > > Here uses 2 separate 'if' statements for seeking, that is, for any > child node of the '', there involves 2 'if' comparations. > Because the child node of the '' is either > '' or '', there would be a slight > optimization when use 'if-else if' construction instead, like below: > > /* optimized src/abg-reader.cc begin */ > for (xmlNodePtr n =3D xmlFirstElementChild(node); > n; > n =3D xmlNextElementSibling(n)) > { > if (xmlStrEqual(n->name, BAD_CAST("underlying-type"))) > { > ... > } > else if (xmlStrEqual(n->name, BAD_CAST("enumerator"))) > { > ... > } > } > /* optimized src/abg-reader.cc end */ > > Supposing there has the test case: > > /* test case begin */ > > > > > > > > /* test case end */ > > When parsing the '' xml tag, for the original > 'src/abg-reader.cc', there involves 2 'if' comparations. But involves > only 1 'if' comparation for the optimized 'src/abg-reader.cc'. > > Signed-off-by: Xiaole He > Tested-by: Xiaole He Applied to the master branch. Cheers, --=20 Dodji