Message ID | 20221016064703.67180-1-hexiaole1994@126.com |
---|---|
State | New |
Headers |
Return-Path: <libabigail-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC3713857429 for <patchwork@sourceware.org>; Sun, 16 Oct 2022 06:49:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC3713857429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665902949; bh=XM2XN44HnIofWew0huHsalAkfmhuJqDQC63AZMBiaMs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=IQ2jLLRjtmSuKjh2wnr/a4godTpirujerd/KudBnWL/MWhPqlX1+m7W0K1Jb1aGoV qMVxqJ+1KKMwZ4ekN4r4zF+4/FhWnF0e1RcLAOXAFB2Ds6vr6R7jon93k+EY0mSuob LWTHgL5gCLQrCqPQV0blBF8r7o2TR9pD3Po3jrdI= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from m15113.mail.126.com (m15113.mail.126.com [220.181.15.113]) by sourceware.org (Postfix) with ESMTP id DCA393858D28 for <libabigail@sourceware.org>; Sun, 16 Oct 2022 06:49:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DCA393858D28 Received: from localhost.localdomain (unknown [117.61.19.197]) by smtp3 (Coremail) with SMTP id DcmowAC33sL4qEtj8nS0DA--.17891S2; Sun, 16 Oct 2022 14:47:20 +0800 (CST) To: libabigail@sourceware.org Subject: [PATCH] abg-reader: optimize if construction Date: Sun, 16 Oct 2022 06:47:03 +0000 Message-Id: <20221016064703.67180-1-hexiaole1994@126.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DcmowAC33sL4qEtj8nS0DA--.17891S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF1xXFy7ZrW3Xr48Wr15Arb_yoW5JryUpr Z7GF4ktwn3Gw1ak3Zavr18Zan5XrWfJa1UWrn8Gr1jkr9Yqrs2grWxJw1ftr17tr4xX34Y qrsxtrykC3WxZF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_q2MrUUUUU= X-Originating-IP: [117.61.19.197] X-CM-SenderInfo: 5kh0xt5rohimizu6ij2wof0z/1tbijhmcBlpEHGtnMQAAsy X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project <libabigail.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libabigail>, <mailto:libabigail-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libabigail/> List-Help: <mailto:libabigail-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libabigail>, <mailto:libabigail-request@sourceware.org?subject=subscribe> From: Xiaole He via Libabigail <libabigail@sourceware.org> Reply-To: Xiaole He <hexiaole1994@126.com> Cc: Xiaole He <hexiaole@kylinos.cn>, Xiaole He <hexiaole1994@126.com> Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" <libabigail-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
abg-reader: optimize if construction
|
|
Commit Message
Xiaole He
Oct. 16, 2022, 6:47 a.m. UTC
In 'build_enum_type_decl' function of 'src/abg-reader.cc', the 'for loop' walk through all the child nodes of the '<enum-decl>' for seeking '<underlying-type>' and '<enumerator>': /* 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 = xmlFirstElementChild(node); n; n = 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 '<enum-decl>', there involves 2 'if' comparations. Because the child node of the '<enum-decl>' is either '<underlying-type>' or '<enumerator>', there would be a slight optimization when use 'if-else if' construction instead, like below: /* optimized src/abg-reader.cc begin */ for (xmlNodePtr n = xmlFirstElementChild(node); n; n = 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 */ <abi-instr version='1.0'> <enum-decl name='E' filepath='../../abitests/test-enum0-v0.cc' line='1' column='6' id='type-id-2'> <underlying-type type-id='type-id-1'/> <enumerator name='e0' value='0'/> <enumerator name='e2' value='1'/> </enum-decl> </abi-instr> /* test case end */ When parsing the '<underlying-type>' 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 <hexiaole@kylinos.cn> Tested-by: Xiaole He <hexiaole@kylinos.cn> --- src/abg-reader.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
Hello Xiaole, Xiaole He via Libabigail <libabigail@sourceware.org> a écrit: > In 'build_enum_type_decl' function of 'src/abg-reader.cc', the > 'for loop' walk through all the child nodes of the '<enum-decl>' for > seeking '<underlying-type>' and '<enumerator>': > > /* 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 = xmlFirstElementChild(node); > n; > n = 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 '<enum-decl>', there involves 2 'if' comparations. > Because the child node of the '<enum-decl>' is either > '<underlying-type>' or '<enumerator>', there would be a slight > optimization when use 'if-else if' construction instead, like below: > > /* optimized src/abg-reader.cc begin */ > for (xmlNodePtr n = xmlFirstElementChild(node); > n; > n = 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 */ > <abi-instr version='1.0'> > <enum-decl name='E' filepath='../../abitests/test-enum0-v0.cc' line='1' column='6' id='type-id-2'> > <underlying-type type-id='type-id-1'/> > <enumerator name='e0' value='0'/> > <enumerator name='e2' value='1'/> > </enum-decl> > </abi-instr> > /* test case end */ > > When parsing the '<underlying-type>' 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 <hexiaole@kylinos.cn> > Tested-by: Xiaole He <hexiaole@kylinos.cn> Applied to the master branch. Cheers,
Thank you for reviewing. At 2022-10-17 22:14:35, "Dodji Seketeli" <dodji@seketeli.org> wrote: >Hello Xiaole, > >Xiaole He via Libabigail <libabigail@sourceware.org> a écrit: > >> In 'build_enum_type_decl' function of 'src/abg-reader.cc', the >> 'for loop' walk through all the child nodes of the '<enum-decl>' for >> seeking '<underlying-type>' and '<enumerator>': >> >> /* 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 = xmlFirstElementChild(node); >> n; >> n = 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 '<enum-decl>', there involves 2 'if' comparations. >> Because the child node of the '<enum-decl>' is either >> '<underlying-type>' or '<enumerator>', there would be a slight >> optimization when use 'if-else if' construction instead, like below: >> >> /* optimized src/abg-reader.cc begin */ >> for (xmlNodePtr n = xmlFirstElementChild(node); >> n; >> n = 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 */ >> <abi-instr version='1.0'> >> <enum-decl name='E' filepath='../../abitests/test-enum0-v0.cc' line='1' column='6' id='type-id-2'> >> <underlying-type type-id='type-id-1'/> >> <enumerator name='e0' value='0'/> >> <enumerator name='e2' value='1'/> >> </enum-decl> >> </abi-instr> >> /* test case end */ >> >> When parsing the '<underlying-type>' 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 <hexiaole@kylinos.cn> >> Tested-by: Xiaole He <hexiaole@kylinos.cn> > >Applied to the master branch. > >Cheers, > >-- > Dodji
diff --git a/src/abg-reader.cc b/src/abg-reader.cc index b55808b9..4afa427a 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -4602,8 +4602,7 @@ build_enum_type_decl(read_context& ctxt, base_type_id = CHAR_STR(a); continue; } - - if (xmlStrEqual(n->name, BAD_CAST("enumerator"))) + else if (xmlStrEqual(n->name, BAD_CAST("enumerator"))) { string name; int64_t value = 0;