public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
	 maennich@google.com
Subject: [PATCH 3/4] XML writer: improve slightly emission of top-level declarations
Date: Fri, 21 Jan 2022 17:30:04 +0000	[thread overview]
Message-ID: <20220121173005.3196387-4-gprocida@google.com> (raw)
In-Reply-To: <20220121173005.3196387-1-gprocida@google.com>

In the loop that emits declarations, the iterator already points to a
decl_base_sptr, there is no need to do another dynamic_cast. It is
also possible to simplify the loop and its conditionals.

There is no change to tests or behaviour.

	* src/abg-writer.cc (decl_is_emitted): Make decl_base_sptr
	argument a const reference.
	(write_translation_unit): Eliminate a typedef and just use a
	range-for loop without the extra dynamic cast for the non-type
	case. Use else instead of continue to make it clear there are
	only two possibilities.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-writer.cc | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 53adca24..44959a02 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -733,7 +733,7 @@ public:
   /// @return true if the decl has already been emitted, false
   /// otherwise.
   bool
-  decl_is_emitted(decl_base_sptr& decl) const
+  decl_is_emitted(const decl_base_sptr& decl) const
   {
     ABG_ASSERT(!is_type(decl));
     string repr = get_pretty_representation(decl, true);
@@ -2440,12 +2440,11 @@ write_translation_unit(write_context&		ctxt,
 				 ctxt, indent + c.get_xml_element_indent());
 
   typedef scope_decl::declarations declarations;
-  typedef declarations::const_iterator const_iterator;
-  const declarations& d = tu.get_global_scope()->get_sorted_member_decls();
+  const declarations& decls = tu.get_global_scope()->get_sorted_member_decls();
 
-  for (const_iterator i = d.begin(); i != d.end(); ++i)
+  for (const decl_base_sptr& decl : decls)
     {
-      if (type_base_sptr t = is_type(*i))
+      if (type_base_sptr t = is_type(decl))
 	{
 	  // Emit declaration-only classes that are needed. Some of
 	  // these classes can be empty.  Those beasts can be classes
@@ -2456,13 +2455,12 @@ write_translation_unit(write_context&		ctxt,
 		&& !ctxt.type_is_emitted(class_type))
 	      write_type(class_type, ctxt,
 			 indent + c.get_xml_element_indent());
-	  continue;
 	}
-
-      if (decl_base_sptr d = is_decl(*i))
-	if (ctxt.decl_is_emitted(d))
-	  continue;
-      write_decl(*i, ctxt, indent + c.get_xml_element_indent());
+      else
+	{
+	  if (!ctxt.decl_is_emitted(decl))
+	    write_decl(decl, ctxt, indent + c.get_xml_element_indent());
+	}
     }
 
   write_referenced_types(ctxt, tu, indent, is_last);
-- 
2.34.1.703.g22d0c6ccf7-goog


  parent reply	other threads:[~2022-01-21 17:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 17:30 [PATCH 0/4] small XML writer changes Giuliano Procida
2022-01-21 17:30 ` [PATCH 1/4] XML writer: remove type_hasher and remaining comment Giuliano Procida
2022-02-25  9:37   ` Dodji Seketeli
2022-01-21 17:30 ` [PATCH 2/4] XML writer: drop write_elf_symbols_table variable emitted_syms Giuliano Procida
2022-02-25  9:50   ` Dodji Seketeli
2022-01-21 17:30 ` Giuliano Procida [this message]
2022-02-25  9:52   ` [PATCH 3/4] XML writer: improve slightly emission of top-level declarations Dodji Seketeli
2022-01-21 17:30 ` [PATCH 4/4] XML writer: do not create extra temporary referenced type shared_ptr Giuliano Procida
2022-02-25  9:52   ` Dodji Seketeli

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=20220121173005.3196387-4-gprocida@google.com \
    --to=gprocida@google.com \
    --cc=dodji@seketeli.org \
    --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).