[PATCH, applying to mainline] ir: Cache internal name for several types

Dodji Seketeli dodji@redhat.com
Mon Feb 12 21:31:42 GMT 2024


Hello,

Profiling showed that computing function type names while sorting
types prior to type hashing was taking a lot of time.  Caching
function, reference, pointers and qualified type names reduces that
time a lot.

This is what this patch does, in prevision for the up coming type
hashing patch.

	* src/abg-ir.cc ({qualified_type_def, pointer_type_def,
	reference_type_def}::get_qualified_name): Cache the internal
	qualified type name for non-canonicalized types.
	(function_type::get_cached_name): Cache the internal function type
	name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applying to the master branch.
---
 src/abg-ir.cc | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index f4d9174f..9f053aef 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -17241,7 +17241,8 @@ qualified_type_def::get_qualified_name(bool internal) const
 	  // We are asked to return a temporary *internal* name.
 	  // Lets compute it and return a reference to where it's
 	  // stored.
-	  priv_->temporary_internal_name_ =
+	  if (priv_->temporary_internal_name_.empty())
+	    priv_->temporary_internal_name_ =
 	      env.intern(build_name(true, /*internal=*/true));
 	  return priv_->temporary_internal_name_;
 	}
@@ -17734,7 +17735,8 @@ pointer_type_def::get_qualified_name(bool internal) const
 	  // cache where we store its name at each invocation of this
 	  // function.
 	  if (pointed_to_type)
-	    priv_->temp_internal_qualified_name_ =
+	    if (priv_->temp_internal_qualified_name_.empty())
+	      priv_->temp_internal_qualified_name_ =
 		pointer_declaration_name(this,
 					 /*variable_name=*/"",
 					 /*qualified_name=*/
@@ -18141,14 +18143,15 @@ reference_type_def::get_qualified_name(bool internal) const
 	  // cache where we store its name at each invocation of this
 	  // function.
 	  if (pointed_to_type)
-	    priv_->temp_internal_qualified_name_ =
-	      get_name_of_reference_to_type(*pointed_to_type,
-					    is_lvalue(),
-					    /*qualified_name=*/
-					    is_typedef(pointed_to_type)
-					    ? false
-					    : true,
-					    /*internal=*/true);
+	    if (priv_->temp_internal_qualified_name_.empty())
+	      priv_->temp_internal_qualified_name_ =
+		get_name_of_reference_to_type(*pointed_to_type,
+					      is_lvalue(),
+					      /*qualified_name=*/
+					      is_typedef(pointed_to_type)
+					      ? false
+					      : true,
+					      /*internal=*/true);
 	  return priv_->temp_internal_qualified_name_;
 	}
     }
@@ -21550,9 +21553,9 @@ function_type::get_cached_name(bool internal) const
 	}
       else
 	{
-	  priv_->temp_internal_cached_name_ =
-	    get_function_type_name(this,
-				   /*internal=*/true);
+	  if (priv_->temp_internal_cached_name_.empty())
+	    priv_->temp_internal_cached_name_ =
+	      get_function_type_name(this, /*internal=*/true);
 	  return priv_->temp_internal_cached_name_;
 	}
     }
-- 
2.39.3


-- 
		Dodji



More information about the Libabigail mailing list