From 09c7a773a3eafe81a4ef353e49d316de8e37037e Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 19 Apr 2021 12:56:45 +0200 Subject: [PATCH] reader: Use xmlFirstElementChild and xmlNextElementSibling rather than xml::advance_to_next_sibling_element 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; -- 2.43.5