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 4/4] XML writer: do not create extra temporary referenced type shared_ptr
Date: Fri, 21 Jan 2022 17:30:05 +0000	[thread overview]
Message-ID: <20220121173005.3196387-5-gprocida@google.com> (raw)
In-Reply-To: <20220121173005.3196387-1-gprocida@google.com>

In the loop of write_referenced_types temporary shared_ptr objects are
created. In the case of a declaration, two shared_ptrs are created. It
is possible to code this so only one object is created.

This is a small optimisation with no change to tests or behaviour.

	* src/abg-writer.cc (write_referenced_types): Create temporary
	shared_ptr objects within each conditional branch instead of
	outside the conditionals and within one of the branches.

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

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 44959a02..76c71a0c 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -2321,18 +2321,21 @@ write_referenced_types(write_context &		ctxt,
 	{
 	  // We handle types which have declarations *and* function
 	  // types here.
-	  type_base_sptr t(*i, noop_deleter());
+	  type_base* t = *i;
 	  if (!ctxt.type_is_emitted(t))
 	    {
-	      if (decl_base* d = get_type_declaration(*i))
+	      if (decl_base* d = get_type_declaration(t))
 		{
 		  decl_base_sptr decl(d, noop_deleter());
 		  write_decl_in_scope(decl, ctxt,
 				      indent + c.get_xml_element_indent());
 		}
-	      else if (function_type_sptr fn_type = is_function_type(t))
-		write_function_type(fn_type, ctxt,
-				    indent + c.get_xml_element_indent());
+	      else if (function_type* f = is_function_type(t))
+		{
+		  function_type_sptr fn_type(f, noop_deleter());
+		  write_function_type(fn_type, ctxt,
+				      indent + c.get_xml_element_indent());
+		}
 	      else
 		ABG_ASSERT_NOT_REACHED;
 	    }
-- 
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 ` [PATCH 3/4] XML writer: improve slightly emission of top-level declarations Giuliano Procida
2022-02-25  9:52   ` Dodji Seketeli
2022-01-21 17:30 ` Giuliano Procida [this message]
2022-02-25  9:52   ` [PATCH 4/4] XML writer: do not create extra temporary referenced type shared_ptr 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-5-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).