public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@seketeli.org>
To: Giuliano Procida <gprocida@google.com>
Cc: "Matthias Männich" <maennich@google.com>,
	"Giuliano Procida via Libabigail" <libabigail@sourceware.org>,
	kernel-team@android.com
Subject: [PATCH 2/3] reader: Use xmlFirstElementChild and xmlNextElementSibling rather than xml::advance_to_next_sibling_element
Date: Mon, 19 Apr 2021 16:01:36 +0200	[thread overview]
Message-ID: <87blaatltr.fsf_-_@seketeli.org> (raw)
In-Reply-To: <87k0oytmsf.fsf@seketeli.org> (Dodji Seketeli's message of "Mon,  19 Apr 2021 15:40:48 +0200")

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(-)

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<char*>(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.30.0



-- 
		Dodji

  parent reply	other threads:[~2021-04-19 14:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31  9:23 [PATCH] XML reader: improve XML node traversal Giuliano Procida
2021-03-31 14:24 ` Matthias Maennich
2021-03-31 16:58   ` Giuliano Procida
2021-03-31 17:04 ` [PATCH v2] " Giuliano Procida
2021-04-06 11:48   ` Dodji Seketeli
2021-04-06 14:35     ` Giuliano Procida
2021-04-06 16:22       ` [PATCH v3] " Giuliano Procida
2021-04-06 17:39         ` [PATCH v4] " Giuliano Procida
2021-04-15 14:12       ` [PATCH v2, " Dodji Seketeli
2021-04-16 12:03         ` Giuliano Procida
2021-04-19 13:40           ` Dodji Seketeli
2021-04-19 14:00             ` Subject: [PATCH 1/3] reader: Handle 'abi-corpus' element being possibly empty Dodji Seketeli
2021-04-19 14:01             ` Dodji Seketeli [this message]
2021-04-19 14:03             ` [PATCH 3/3] reader: Use xmlFirstElementChild/xmlNextElementSibling to iterate over children elements Dodji Seketeli
2021-04-20  6:52               ` Giuliano Procida
2021-04-20  9:46                 ` Dodji Seketeli
2021-05-03 15:18                   ` Dodji Seketeli
2021-05-04 11:13                     ` Giuliano Procida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blaatltr.fsf_-_@seketeli.org \
    --to=dodji@seketeli.org \
    --cc=gprocida@google.com \
    --cc=kernel-team@android.com \
    --cc=libabigail@sourceware.org \
    --cc=maennich@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).