From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id B0AB63858D33 for ; Mon, 27 Nov 2023 03:39:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0AB63858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B0AB63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701056342; cv=none; b=JEngIcbuh7wzqyPOOMuoedUkv05cVA7v5Kx8MExd9TLLfyTTq2ISp8jLvNDrXPJH4YoTSM3T6Ak5nSUbu1CoI3iNd9upNLKFOiZxA2u6bBr3sju4PpjyT0ldCxKXVaZSZ4j9wHZbm79hWg/2VYYNzhbIY2IVy/ZHBd8c6U20Zcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701056342; c=relaxed/simple; bh=1O2lCDGSreZl9JNQfIF20F+1rIpr9fTCmTnBPAh/S1w=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=bp0liIzUlUl/r0h4lKRhTHawZgGM5a8LOIUhILKMNkKmqJTK6RDNVhZghtGTgw2tnMpczZ4SXyVKlUL1YDDrqNnBHc/GzjkHWskqX1cC3iZ03VTaPmMJf1eY5ecsx4jIwFXfvKuNfr1lJGKKcQgtQYx4XhjLDQf5dEx91zTar3o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BBC5120116 for ; Mon, 27 Nov 2023 03:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701056339; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zxnYp03++ooW9bZnjD3kdVWhIUoCiPCO9W9lwZ8mYpU=; b=1Dwtr7gjdlYI57mssK85Da9CniuqaJBhZCmmakgtBTjtD7lFssfsiJLG9FHSKAGS61vpk7 8vJBx3jhbwjmAV4F/xplb2tQtaXgvdyVjWg5GdSIve66PT/5Q2nxYEsUVw9whfB6420+UK eYctiJWR2NmWLjrVb2wqQgrWMIQDqBc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701056339; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zxnYp03++ooW9bZnjD3kdVWhIUoCiPCO9W9lwZ8mYpU=; b=CB8ybFk+9LKUqNUAA6cTWoQNVmtSWcgLhxo/nW87tUQSnZW8YmWLOBtokbzzilzrdC0MiC lVAZT4zosAChfVBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8FD8D13488 for ; Mon, 27 Nov 2023 03:38:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id h3xeIVMPZGUsXgAAD6G6ig (envelope-from ) for ; Mon, 27 Nov 2023 03:38:59 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [gdb/tui] Use const std::string for string literals in tui-stack.c Date: Mon, 27 Nov 2023 04:39:07 +0100 Message-Id: <20231127033908.13249-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 16.50 X-Spamd-Result: default: False [16.50 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_LONG(3.50)[1.000]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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 them upper-case. Tested on x86_64-linux. --- gdb/tui/tui-stack.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c index 76b8f066abb..723d6268aad 100644 --- a/gdb/tui/tui-stack.c +++ b/gdb/tui/tui-stack.c @@ -40,12 +40,12 @@ #include "gdb_curses.h" -#define PROC_PREFIX "In: " -#define LINE_PREFIX "L" -#define PC_PREFIX "PC: " +static const std::string PROC_PREFIX = "In: "; +static const std::string LINE_PREFIX = "L"; +static const std::string PC_PREFIX = "PC: "; /* Strings to display in the TUI status line. */ -#define SINGLE_KEY "(SingleKey)" +static const std::string SINGLE_KEY = "(SingleKey)"; /* Minimum/Maximum length of some fields displayed in the TUI status line. */ @@ -107,16 +107,15 @@ tui_locator_window::make_status_line () const int pc_width = pc_out.size (); /* First determine the amount of proc name width we have available. - The +1 are for a space separator between fields. - The -1 are to take into account the \0 counted by sizeof. */ + The +1 are for a space separator between fields. */ proc_width = (status_size - (target_width + 1) - (pid_width + 1) - - (sizeof (PROC_PREFIX) - 1 + 1) - - (sizeof (LINE_PREFIX) - 1 + line_width + 1) - - (sizeof (PC_PREFIX) - 1 + pc_width + 1) + - (PROC_PREFIX.size () + 1) + - (LINE_PREFIX.size () + line_width + 1) + - (PC_PREFIX.size () + pc_width + 1) - (tui_current_key_mode == TUI_SINGLE_KEY_MODE - ? (sizeof (SINGLE_KEY) - 1 + 1) + ? (SINGLE_KEY.size () + 1) : 0)); /* If there is no room to print the function name, try by removing @@ -131,11 +130,11 @@ tui_locator_window::make_status_line () const pid_width = 0; if (proc_width <= MIN_PROC_WIDTH) { - proc_width += pc_width + sizeof (PC_PREFIX) - 1 + 1; + proc_width += pc_width + PC_PREFIX.size () + 1; pc_width = 0; if (proc_width < 0) { - proc_width += line_width + sizeof (LINE_PREFIX) - 1 + 1; + proc_width += line_width + LINE_PREFIX.size () + 1; line_width = 0; if (proc_width < 0) proc_width = 0; @@ -156,7 +155,7 @@ tui_locator_window::make_status_line () const /* Show whether we are in SingleKey mode. */ if (tui_current_key_mode == TUI_SINGLE_KEY_MODE) { - string.puts (SINGLE_KEY); + string.puts (SINGLE_KEY.c_str ()); string.puts (" "); } @@ -165,19 +164,19 @@ tui_locator_window::make_status_line () const { const std::string &proc_name = tui_location.proc_name (); if (proc_name.size () > proc_width) - string.printf ("%s%*.*s* ", PROC_PREFIX, + string.printf ("%s%*.*s* ", PROC_PREFIX.c_str (), 1 - proc_width, proc_width - 1, proc_name.c_str ()); else - string.printf ("%s%*.*s ", PROC_PREFIX, + string.printf ("%s%*.*s ", PROC_PREFIX.c_str (), -proc_width, proc_width, proc_name.c_str ()); } if (line_width > 0) - string.printf ("%s%*.*s ", LINE_PREFIX, + string.printf ("%s%*.*s ", LINE_PREFIX.c_str (), -line_width, line_width, line_buf); if (pc_width > 0) { - string.puts (PC_PREFIX); + string.puts (PC_PREFIX.c_str ()); string.puts (pc_buf); } base-commit: 476bf7d5e6661b06eb9f8de9258cf48fd81919af -- 2.35.3