[4/4] XML writer: do not create extra temporary referenced type shared_ptr

Message ID 20220121173005.3196387-5-gprocida@google.com
State New
Headers
Series small XML writer changes |

Commit Message

Giuliano Procida Jan. 21, 2022, 5:30 p.m. UTC
  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(-)
  

Comments

Dodji Seketeli Feb. 25, 2022, 9:52 a.m. UTC | #1
Giuliano Procida <gprocida@google.com> a écrit:

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

Applied to master, thanks!

[...]

Cheers,
  

Patch

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;
 	    }