U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Cc: Sean Anderson <seanga2@gmail.com>, Simon Glass <sjg@chromium.org>,
	Tom Rini <trini@konsulko.com>
Subject: [RFC PATCH 02/11] cmd: ini: Use strlower() to normalise case
Date: Fri, 15 May 2026 14:32:53 -0600	[thread overview]
Message-ID: <20260515203311.2555651-3-sjg@chromium.org> (raw)
In-Reply-To: <20260515203311.2555651-1-sjg@chromium.org>

ini_handler() lowercases four strings when CONFIG_INI_CASE_INSENSITIVE
is set, each with a hand-rolled loop whose strlen() in the condition
makes it quadratic in the string length.

Replace each loop with strlower() and fold the #ifdef pair into a
runtime IS_ENABLED() check so the body reads linearly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/ini.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/cmd/ini.c b/cmd/ini.c
index 96399017691..cf0a3ce8b3d 100644
--- a/cmd/ini.c
+++ b/cmd/ini.c
@@ -202,22 +202,17 @@ static int ini_parse(char *filestart, size_t filelen,
 static int ini_handler(void *user, char *section, char *name, char *value)
 {
 	char *requested_section = (char *)user;
-#ifdef CONFIG_INI_CASE_INSENSITIVE
-	int i;
 
-	for (i = 0; i < strlen(requested_section); i++)
-		requested_section[i] = tolower(requested_section[i]);
-	for (i = 0; i < strlen(section); i++)
-		section[i] = tolower(section[i]);
-#endif
+	if (IS_ENABLED(CONFIG_INI_CASE_INSENSITIVE)) {
+		strlower(requested_section);
+		strlower(section);
+	}
 
 	if (!strcmp(section, requested_section)) {
-#ifdef CONFIG_INI_CASE_INSENSITIVE
-		for (i = 0; i < strlen(name); i++)
-			name[i] = tolower(name[i]);
-		for (i = 0; i < strlen(value); i++)
-			value[i] = tolower(value[i]);
-#endif
+		if (IS_ENABLED(CONFIG_INI_CASE_INSENSITIVE)) {
+			strlower(name);
+			strlower(value);
+		}
 		env_set(name, value);
 		printf("ini: Imported %s as %s\n", name, value);
 	}
-- 
2.43.0


  parent reply	other threads:[~2026-05-15 20:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 20:32 [RFC PATCH 00/11] Tidy command option parsing and use it a bit Simon Glass
2026-05-15 20:32 ` [RFC PATCH 01/11] lib: string: Add strlower() Simon Glass
2026-05-15 20:32 ` Simon Glass [this message]
2026-05-15 20:32 ` [RFC PATCH 03/11] fs: fat: Use strlower() to normalise case Simon Glass
2026-05-15 20:32 ` [RFC PATCH 04/11] boot: pxe_utils: Use strlower() in get_string() Simon Glass
2026-05-15 20:32 ` [RFC PATCH 05/11] lib: getopt: Permute by default with inline reorder Simon Glass
2026-05-15 21:37   ` Sean Anderson
2026-05-20 20:42     ` Simon Glass
2026-05-15 20:32 ` [RFC PATCH 06/11] lib: getopt: Add getopt_pop() helper Simon Glass
2026-05-15 21:40   ` Sean Anderson
2026-05-20 20:41     ` Simon Glass
2026-05-15 20:32 ` [RFC PATCH 07/11] cmd: echo: Use getopt() with '+' prefix for option parsing Simon Glass
2026-05-15 21:58   ` Sean Anderson
2026-05-20 20:41     ` Simon Glass
2026-05-15 20:32 ` [RFC PATCH 08/11] cmd: hash: Use getopt() " Simon Glass
2026-05-15 20:33 ` [RFC PATCH 09/11] cmd: nvedit: Use getopt() in env grep Simon Glass
2026-05-15 20:33 ` [RFC PATCH 10/11] cmd: nvedit: Use getopt() in env export and env import Simon Glass
2026-05-15 20:33 ` [RFC PATCH 11/11] doc: commands: Recommend getopt() for option parsing Simon Glass
2026-05-15 21:43 ` [RFC PATCH 00/11] Tidy command option parsing and use it a bit Tom Rini
2026-05-15 21:59   ` Sean Anderson
2026-05-15 22:06     ` Sean Anderson
2026-05-15 22:21       ` Tom Rini
2026-05-15 22:27         ` Sean Anderson
2026-05-20 20:40           ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260515203311.2555651-3-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=seanga2@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox