From: Tom Tromey Date: Fri, 12 Apr 2024 02:00:09 +0000 (-0600) Subject: Remove some unnecessary allocations from cpname_state::parse_number X-Git-Tag: gdb-15-branchpoint~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25113e2d040fad868409c3e17262ee007fc8658a;p=thirdparty%2Fbinutils-gdb.git Remove some unnecessary allocations from cpname_state::parse_number 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 --- diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index e0b34aaa0c7..b254d63bfec 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -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);