aboutsummaryrefslogtreecommitdiff
path: root/gdb/block.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-01-16 17:04:39 -0700
committerTom Tromey <tom@tromey.com>2023-02-19 12:51:05 -0700
commitf52688890edd7c587ec11cf1d565f235e41a6c43 (patch)
treec413367521a7229ef06bf156bd688aa0cc5acb5c /gdb/block.c
parent4aabc4166430fed52e9a2e4042147e3480f9178a (diff)
downloadgdb-f52688890edd7c587ec11cf1d565f235e41a6c43.zip
gdb-f52688890edd7c587ec11cf1d565f235e41a6c43.tar.gz
gdb-f52688890edd7c587ec11cf1d565f235e41a6c43.tar.bz2
Avoid extra allocations in block
block_set_scope and block_set_using unconditionally allocate the block namespace object. However, this isn't truly needed, so arrange to only allocate when it is.
Diffstat (limited to 'gdb/block.c')
-rw-r--r--gdb/block.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gdb/block.c b/gdb/block.c
index 751f67d..f24a2b5 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -320,6 +320,12 @@ void
block_set_scope (struct block *block, const char *scope,
struct obstack *obstack)
{
+ if (scope == nullptr || scope[0] == '\0')
+ {
+ /* Don't bother. */
+ return;
+ }
+
block_initialize_namespace (block, obstack);
block->namespace_info ()->scope = scope;
@@ -346,6 +352,12 @@ block_set_using (struct block *block,
struct using_direct *using_decl,
struct obstack *obstack)
{
+ if (using_decl == nullptr)
+ {
+ /* Don't bother. */
+ return;
+ }
+
block_initialize_namespace (block, obstack);
block->namespace_info ()->using_decl = using_decl;