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.
This commit is contained in:
Tom Tromey
2023-01-16 17:04:39 -07:00
parent 4aabc41664
commit f52688890e

View 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;