mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Goddard Rosa" <andre.goddard@gmail.com>
To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org
Cc: "André Goddard Rosa" <andre.goddard@gmail.com>,
	"Joe Perches" <joe@perches.com>,
	"Frederic Weisbecker" <fweisbec@gmail.com>,
	"Andrew Morton" <akpm@linux-foundation.org>
Subject: [PATCH 1/2] string: simplify stricmp()
Date: Sat, 16 Jan 2010 18:57:00 -0200	[thread overview]
Message-ID: <16ee7c5e218e89f22a28247e4bd3877355f5ae5c.1263675077.git.andre.goddard@gmail.com> (raw)
In-Reply-To: <cover.1263675077.git.andre.goddard@gmail.com>

Removes 32 bytes on core2 with gcc 4.4.1:
   text    data     bss     dec     hex filename
   3196       0       0    3196     c7c lib/string-BEFORE.o
   3164       0       0    3164     c5c lib/string-AFTER.o

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
cc: Joe Perches <joe@perches.com>
cc: Frederic Weisbecker <fweisbec@gmail.com>
cc: Andrew Morton <akpm@linux-foundation.org>
---
 lib/string.c |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index a1cdcfc..0f86245 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -36,25 +36,21 @@ int strnicmp(const char *s1, const char *s2, size_t len)
 	/* Yes, Virginia, it had better be unsigned */
 	unsigned char c1, c2;
 
-	c1 = c2 = 0;
-	if (len) {
-		do {
-			c1 = *s1;
-			c2 = *s2;
-			s1++;
-			s2++;
-			if (!c1)
-				break;
-			if (!c2)
-				break;
-			if (c1 == c2)
-				continue;
-			c1 = tolower(c1);
-			c2 = tolower(c2);
-			if (c1 != c2)
-				break;
-		} while (--len);
-	}
+	if (!len)
+		return 0;
+
+	do {
+		c1 = *s1++;
+		c2 = *s2++;
+		if (!c1 || !c2)
+			break;
+		if (c1 == c2)
+			continue;
+		c1 = tolower(c1);
+		c2 = tolower(c2);
+		if (c1 != c2)
+			break;
+	} while (--len);
 	return (int)c1 - (int)c2;
 }
 EXPORT_SYMBOL(strnicmp);
-- 
1.6.6.201.g56119


  reply	other threads:[~2010-01-17 21:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-16 20:56 [PATCH 0/2] Fix recently introduced strnstr() to not search past NUL André Goddard Rosa
2010-01-16 20:57 ` André Goddard Rosa [this message]
2010-01-23  0:27   ` [PATCH 1/2] string: simplify stricmp() Andrew Morton
2010-01-23  1:47     ` Linus Torvalds
2010-01-16 20:57 ` [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator André Goddard Rosa
2010-01-17 23:47   ` Alex Riesen
2010-01-18  1:47   ` Li Zefan
2010-01-18 15:10     ` André Goddard Rosa

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=16ee7c5e218e89f22a28247e4bd3877355f5ae5c.1263675077.git.andre.goddard@gmail.com \
    --to=andre.goddard@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®