[2/4] abg-writer: refactor recording of unemitted types

Message ID 20210910112325.806676-3-gprocida@google.com
State New
Headers
Series Looking at equality and hashing |

Commit Message

Giuliano Procida Sept. 10, 2021, 11:23 a.m. UTC
  The code fragment

if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
  referenced_types_to_emit.insert(*i);

appears 5 times. This commit inlines the insertion into the helper
function which is also renamed.

	* src/abg-writer.cc (referenced_type_should_be_emitted):
	Replaced by record_unemitted_type.
	(record_unemitted_type): Replacement function that also takes
	care of inserting the type into the set.
	(write_translation_unit): Replace calls to
	referenced_type_should_be_emitted and inserts with calls to
	record_unemitted_type.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-writer.cc | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
  

Patch

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index d23f4fd6..795ca685 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -2248,10 +2248,12 @@  write_canonical_types_of_scope(const scope_decl	&scope,
 }
 
 /// Test if a type referenced in a given translation unit should be
-/// emitted or not.
+/// emitted and record it if so.
 ///
 /// This is a subroutine of @ref write_translation_unit.
 ///
+/// @param types the set of types to update.
+///
 /// @param t the type to consider.
 ///
 /// @param ctxt the write context to consider.
@@ -2260,20 +2262,18 @@  write_canonical_types_of_scope(const scope_decl	&scope,
 ///
 /// @param tu_is_last true if @p tu is the last translation unit being
 /// emitted.
-///
-/// @return true iff @p t is to be emitted.
-static bool
-referenced_type_should_be_emitted(const type_base *t,
-				  const write_context& ctxt,
-				  const translation_unit& tu,
-				  bool tu_is_last)
+static void
+record_unemitted_type(type_ptr_set_type& types,
+		      const type_base *t,
+		      const write_context& ctxt,
+		      const translation_unit& tu,
+		      bool tu_is_last)
 {
   if ((tu_is_last || t->get_translation_unit()->get_absolute_path()
        == tu.get_absolute_path())
       && !ctxt.type_is_emitted(t)
       && !ctxt.decl_only_type_is_emitted(t))
-    return true;
-  return false;
+    types.insert(t);
 }
 
 /// Serialize a translation unit to an output stream.
@@ -2389,22 +2389,19 @@  write_translation_unit(write_context&		ctxt,
 	 ctxt.get_referenced_types().begin();
        i != ctxt.get_referenced_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   for (fn_type_ptr_set_type::const_iterator i =
 	 ctxt.get_referenced_function_types().begin();
        i != ctxt.get_referenced_function_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   for (type_ptr_set_type::const_iterator i =
 	 ctxt.get_referenced_non_canonical_types().begin();
        i != ctxt.get_referenced_non_canonical_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   // Ok, now let's emit the referenced type for good.
   while (!referenced_types_to_emit.empty())
@@ -2459,15 +2456,13 @@  write_translation_unit(write_context&		ctxt,
 	     ctxt.get_referenced_types().begin();
 	   i != ctxt.get_referenced_types().end();
 	   ++i)
-	if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-	  referenced_types_to_emit.insert(*i);
+        record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
       for (type_ptr_set_type::const_iterator i =
 	     ctxt.get_referenced_non_canonical_types().begin();
 	   i != ctxt.get_referenced_non_canonical_types().end();
 	   ++i)
-	if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-	  referenced_types_to_emit.insert(*i);
+        record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
     }
 
   // Now handle all function types that were not only referenced by