]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Avoid extra allocations in block
authorTom Tromey <tom@tromey.com>
Tue, 17 Jan 2023 00:04:39 +0000 (17:04 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 19 Feb 2023 19:51:05 +0000 (12:51 -0700)
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.

gdb/block.c

index 751f67d30f72decf7197dd15539d6f857e87f51a..f24a2b5d0848f154266c8279f67fec5c81c65119 100644 (file)
@@ -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;