From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 5B2223858D20; Sun, 19 Feb 2023 23:37:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B2223858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676849824; bh=9/CVPYln2wg9QXmrKlWMG/zXpR4BQmIJBBX46QHnr10=; h=From:To:Subject:Date:From; b=ofuQYW8RtEjbvuQ3+UhDWQRScLc2OnjviOn7b1t7azk/+1/K3VpgryXyVVf7aJUut Kbkm3uh9x6ikuZSyzaHirHhHKU9S/iddHC2TYWmJG24jUalamcLsxJzTClJxsG9Q7O n3L8zqoajMMG/IAH/i5Rg1u93g/ImPtdOQUjUUes= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Avoid extra allocations in block X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 4aabc4166430fed52e9a2e4042147e3480f9178a X-Git-Newrev: f52688890edd7c587ec11cf1d565f235e41a6c43 Message-Id: <20230219233704.5B2223858D20@sourceware.org> Date: Sun, 19 Feb 2023 23:37:04 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df52688890edd= 7c587ec11cf1d565f235e41a6c43 commit f52688890edd7c587ec11cf1d565f235e41a6c43 Author: Tom Tromey Date: Mon Jan 16 17:04:39 2023 -0700 Avoid extra allocations in block =20 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. Diff: --- gdb/block.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gdb/block.c b/gdb/block.c index 751f67d30f7..f24a2b5d084 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 =3D=3D nullptr || scope[0] =3D=3D '\0') + { + /* Don't bother. */ + return; + } + block_initialize_namespace (block, obstack); =20 block->namespace_info ()->scope =3D scope; @@ -346,6 +352,12 @@ block_set_using (struct block *block, struct using_direct *using_decl, struct obstack *obstack) { + if (using_decl =3D=3D nullptr) + { + /* Don't bother. */ + return; + } + block_initialize_namespace (block, obstack); =20 block->namespace_info ()->using_decl =3D using_decl;