From patchwork Mon Apr 19 14:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 43039 Return-Path: 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 E1A60385E00D; Mon, 19 Apr 2021 14:01:43 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by sourceware.org (Postfix) with ESMTPS id 9EFAB385E00D for ; Mon, 19 Apr 2021 14:01:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9EFAB385E00D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dodji@seketeli.org X-Originating-IP: 88.120.130.27 Received: from localhost (unknown [88.120.130.27]) (Authenticated sender: dodji@seketeli.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 477F91C0004; Mon, 19 Apr 2021 14:01:37 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id BD3DE580100; Mon, 19 Apr 2021 16:01:36 +0200 (CEST) From: Dodji Seketeli To: Giuliano Procida Subject: [PATCH 2/3] reader: Use xmlFirstElementChild and xmlNextElementSibling rather than xml::advance_to_next_sibling_element Organization: Me, myself and I References: <20210331092352.619148-1-gprocida@google.com> <20210331170454.951900-1-gprocida@google.com> <8735w3vdkv.fsf@seketeli.org> <87o8eftz5v.fsf_-_@seketeli.org> <87k0oytmsf.fsf@seketeli.org> X-Operating-System: Fedora 34 X-URL: http://www.seketeli.net/~dodji Date: Mon, 19 Apr 2021 16:01:36 +0200 In-Reply-To: <87k0oytmsf.fsf@seketeli.org> (Dodji Seketeli's message of "Mon, 19 Apr 2021 15:40:48 +0200") Message-ID: <87blaatltr.fsf_-_@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: kernel-team@android.com, Giuliano Procida via Libabigail , Matthias =?utf-8?q?M=C3=A4nnich?= Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Hello, The xml::advance_to_next_sibling_element is redundant with the xmlNextElementSibling API of libxml. Similarly, xmlFirstElementChild is redundant with using xml::advance_to_next_sibling_element on the xmlNode::children data member. Let's use the libxml API instead. * include/abg-libxml-utils.h (advance_to_next_sibling_element): Remove the declaration of this function. * src/abg-libxml-utils.cc (go_to_next_sibling_element_or_stay) (advance_to_next_sibling_element): Remove definitions of these functions. * src/abg-reader.cc (read_translation_unit_from_input) (read_elf_needed_from_input, read_corpus_group_from_input): Use xmlNextElementSibling instead of xml::advance_to_next_sibling_element. (read_corpus_from_input): Likewise. Also, use xmlFirstElementChild instead of xml::advance_to_next_sibling_element on the xmlNode::children data member. (read_corpus_group_from_input): use xmlFirstElementChild instead of xml::advance_to_next_sibling_element on the xmlNode::children data member. Signed-off-by: Dodji Seketeli --- include/abg-libxml-utils.h | 3 --- src/abg-libxml-utils.cc | 40 -------------------------------------- src/abg-reader.cc | 12 ++++++------ 3 files changed, 6 insertions(+), 49 deletions(-) diff --git a/include/abg-libxml-utils.h b/include/abg-libxml-utils.h index 69e940f6..7a2e2572 100644 --- a/include/abg-libxml-utils.h +++ b/include/abg-libxml-utils.h @@ -81,9 +81,6 @@ int get_xml_node_depth(xmlNodePtr); #define CHAR_STR(xml_char_str) \ reinterpret_cast(xml_char_str.get()) -xmlNodePtr -advance_to_next_sibling_element(xmlNodePtr node); - void escape_xml_string(const std::string& str, std::string& escaped); diff --git a/src/abg-libxml-utils.cc b/src/abg-libxml-utils.cc index 6b55d3ed..b29d2a85 100644 --- a/src/abg-libxml-utils.cc +++ b/src/abg-libxml-utils.cc @@ -413,45 +413,5 @@ unescape_xml_comment(const std::string& str) return result; } -/// Maybe get the next sibling element node of an XML node, or stay to -/// the same. -/// -/// If there is no next sibling xml element node, the function returns -/// the initial node. -/// -/// @param node the initial node to consider. -/// -/// @return the next sibling node or the initial node @p node. -static xmlNodePtr -go_to_next_sibling_element_or_stay(xmlNodePtr node) -{ - xmlNodePtr n; - for (n = node; n; n = n->next) - { - if (n->type == XML_ELEMENT_NODE) - break; - } - return n ? n : node; -} - -/// Get the next sibling element node of an XML node. -/// -/// If there is no next sibling xml element node, the function returns nil. -/// -/// @param node the XML node to consider. -/// -/// @return the next sibling element node or nil. -xmlNodePtr -advance_to_next_sibling_element(xmlNodePtr node) -{ - if (!node) - return 0; - - xmlNodePtr n = go_to_next_sibling_element_or_stay(node->next); - if (n == 0 || n->type != XML_ELEMENT_NODE) - return 0; - return n; -} - }//end namespace xml }//end namespace abigail diff --git a/src/abg-reader.cc b/src/abg-reader.cc index d2c76a38..f5ed87b2 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1518,7 +1518,7 @@ read_translation_unit_from_input(read_context& ctxt) // from a local invocation of xmlTextReaderExpand. So let's set // ctxt.get_corpus_node to the next child element node of the // corpus that needs to be processed. - node = xml::advance_to_next_sibling_element(node); + node = xmlNextElementSibling(node); ctxt.set_corpus_node(node); } @@ -1718,7 +1718,7 @@ read_elf_needed_from_input(read_context& ctxt, if (node) { result = build_needed(node, needed); - node = xml::advance_to_next_sibling_element(node); + node = xmlNextElementSibling(node); ctxt.set_corpus_node(node); } @@ -1930,7 +1930,7 @@ read_corpus_from_input(read_context& ctxt) // the corpus element that *needs* to be processed. if (node->children) { - xmlNodePtr n = xml::advance_to_next_sibling_element(node->children); + xmlNodePtr n = xmlFirstElementChild(node); ctxt.set_corpus_node(n); } @@ -1996,12 +1996,12 @@ read_corpus_from_input(read_context& ctxt) else { node = ctxt.get_corpus_node(); - node = xml::advance_to_next_sibling_element(node); + node = xmlNextElementSibling(node); if (!node) { node = ctxt.get_corpus_node(); if (node) - node = xml::advance_to_next_sibling_element(node->parent); + node = xmlNextElementSibling(node->parent); } ctxt.set_corpus_node(node); } @@ -2055,7 +2055,7 @@ read_corpus_group_from_input(read_context& ctxt) return nil; //node = xml::get_first_element_sibling_if_text(node->children); - node = xml::advance_to_next_sibling_element(node->children); + node = xmlFirstElementChild(node); ctxt.set_corpus_node(node); corpus_sptr corp;