[2/3] reader: Use xmlFirstElementChild and xmlNextElementSibling rather than xml::advance_to_next_sibling_element
Commit Message
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 <dodji@redhat.com>
---
include/abg-libxml-utils.h | 3 ---
src/abg-libxml-utils.cc | 40 --------------------------------------
src/abg-reader.cc | 12 ++++++------
3 files changed, 6 insertions(+), 49 deletions(-)
@@ -81,9 +81,6 @@ int get_xml_node_depth(xmlNodePtr);
#define CHAR_STR(xml_char_str) \
reinterpret_cast<char*>(xml_char_str.get())
-xmlNodePtr
-advance_to_next_sibling_element(xmlNodePtr node);
-
void
escape_xml_string(const std::string& str,
std::string& escaped);
@@ -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
@@ -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;