]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove some unnecessary allocations from cpname_state::parse_number
authorTom Tromey <tom@tromey.com>
Fri, 12 Apr 2024 02:00:09 +0000 (20:00 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 14 May 2024 19:28:39 +0000 (13:28 -0600)
cpname_state::parse_number allocates nodes for various types and then
only uses one of them.  This patch reduces the number of allocations
by not performing the unnecessary ones.

Approved-By: John Baldwin <jhb@FreeBSD.org>
gdb/cp-name-parser.y

index e0b34aaa0c7b4aa05662298d5280ffd8fb432c98..b254d63bfec70336825a8a1d29bd894ac17c1fe8 100644 (file)
@@ -1290,8 +1290,6 @@ cpname_state::parse_number (const char *p, int len, int parsed_float,
   /* Number of "L" suffixes encountered.  */
   int long_p = 0;
 
-  struct demangle_component *signed_type;
-  struct demangle_component *unsigned_type;
   struct demangle_component *type, *name;
   enum demangle_component_type literal_type;
 
@@ -1362,25 +1360,26 @@ cpname_state::parse_number (const char *p, int len, int parsed_float,
 
   if (long_p == 0)
     {
-      unsigned_type = make_builtin_type ("unsigned int");
-      signed_type = make_builtin_type ("int");
+      if (unsigned_p)
+       type = make_builtin_type ("unsigned int");
+      else
+       type = make_builtin_type ("int");
     }
   else if (long_p == 1)
     {
-      unsigned_type = make_builtin_type ("unsigned long");
-      signed_type = make_builtin_type ("long");
+      if (unsigned_p)
+       type = make_builtin_type ("unsigned long");
+      else
+       type = make_builtin_type ("long");
     }
   else
     {
-      unsigned_type = make_builtin_type ("unsigned long long");
-      signed_type = make_builtin_type ("long long");
+      if (unsigned_p)
+       type = make_builtin_type ("unsigned long long");
+      else
+       type = make_builtin_type ("long long");
     }
 
-   if (unsigned_p)
-     type = unsigned_type;
-   else
-     type = signed_type;
-
    name = make_name (p, len);
    lvalp->comp = fill_comp (literal_type, type, name);