]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/tui] Use const std::string for string literals in tui-stack.c
authorTom de Vries <tdevries@suse.de>
Tue, 28 Nov 2023 15:31:07 +0000 (16:31 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 28 Nov 2023 15:31:07 +0000 (16:31 +0100)
commit1f6ce803887ac8da6d4b5903fa270dfa63c63bbf
tree1c418e75995a9c8fd640928dd6f2788bfea0a623
parent9d4db627b2a6a78f7f7959668da94e79e17a7e34
[gdb/tui] Use const std::string for string literals in tui-stack.c

I noticed in gdb/tui/tui-stack.c a source-level micro-optimization where
strlen with a string literal argument:
...
strlen ("bla")
...
is replaced with sizeof:
...
sizeof ("bla") - 1
...

The benefit of this is that the optimization is also done at O0, but the
drawback is that it makes the expression harder to read.

Use const std::string to encapsulate the string literals, and use
std::string::size () instead.

I tried making the string names (PROC_PREFIX, LINE_PREFIX, PC_PREFIX and
SINGLE_KEY) lower-case, but that clashed with a pre-existing pc_prefix, so
I've left them upper-case.

Tested on x86_64-linux.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
gdb/tui/tui-stack.c