[1/2] gdb: move cheap pointer equality check earlier in types_equal

Message ID 01fc91dbaff9b51a7c3c07b4bd49adbf0ad016b0.1616667144.git.andrew.burgess@embecosm.com
State New
Headers show
Series
  • Value casting changes
Related show

Commit Message

Andrew Burgess March 25, 2021, 10:16 a.m.
I noticed that in types equal we start with a cheap pointer equality
check, then resolve typedefs, then do a series of (semi-)expensive
checks, including checking type names, before, finally performing
another pointer equality check.

We should hoist the second pointer equality check to immediately after
we have resolved typedefs.  This would save performing the more
expensive checks.

This isn't going to give any noticable performance improvement, I just
spotted this in passing and figured I might as well commit the fix.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* gdbtypes.c (types_equal): Move pointer equality check earlier in
	the function.
---
 gdb/ChangeLog  | 5 +++++
 gdb/gdbtypes.c | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

-- 
2.25.4

Comments

Tom Tromey April 1, 2021, 6:06 p.m. | #1
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:


Andrew> 	* gdbtypes.c (types_equal): Move pointer equality check earlier in
Andrew> 	the function.

Looks good.  Thank you.

Tom

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1b2d4836959..f153d9ac210 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4075,6 +4075,10 @@  types_equal (struct type *a, struct type *b)
   if (b->code () == TYPE_CODE_TYPEDEF)
     b = check_typedef (b);
 
+  /* Check if identical after resolving typedefs.  */
+  if (a == b)
+    return true;
+
   /* If after resolving typedefs a and b are not of the same type
      code then they are not equal.  */
   if (a->code () != b->code ())
@@ -4097,10 +4101,6 @@  types_equal (struct type *a, struct type *b)
       && strcmp (a->name (), b->name ()) == 0)
     return true;
 
-  /* Check if identical after resolving typedefs.  */
-  if (a == b)
-    return true;
-
   /* Two function types are equal if their argument and return types
      are equal.  */
   if (a->code () == TYPE_CODE_FUNC)