public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Michal Nazarewicz <mina86@mina86.com>,
	zengzhaoxiu@163.com, linux-kernel@vger.kernel.org
Cc: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
	Borislav Petkov <bp@suse.de>, Michal Hocko <mhocko@suse.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Nicolas Iooss <nicolas.iooss_linux@m4x.org>,
	"Steven Rostedt (Red Hat)" <rostedt@goodmis.org>,
	Gustavo Padovan <gustavo.padovan@collabora.co.uk>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Horacio Mijail Anton Quiles <hmijail@gmail.com>
Subject: Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin
Date: Thu, 30 Jun 2016 12:26:11 -0700	[thread overview]
Message-ID: <1467314771.24287.160.camel@perches.com> (raw)
In-Reply-To: <1467226354.30123.336.camel@linux.intel.com>

On Wed, 2016-06-29 at 21:52 +0300, Andy Shevchenko wrote:
> On Wed, 2016-06-29 at 20:31 +0200, Michal Nazarewicz wrote:
[]
> > tolower macro maps to __tolower function which calls isupper to
> > to determine if character is an upper case letter before converting
> > it to lower case.  This preservers non-letters unchanged which is
> > what you want in usual case.
> > 
> > However, hex_to_bin does not care about non-letter characters so
> > such conversion can be performed as long as (i) upper case letters
> > become lower case, (ii) lower case letters are unchanged and (iii)
> > non-letters stay non-letters.
> > 
> > This is exactly what _tolower function does and using it makes it
> > possible to avoid _ctype table lookup performed by the isupper
> > table.
> > 
> > Furthermore, since _tolower conversion is done unconditionally, this
> > also eliminates a single branch.
> This change I agree with since _tolower() is specific for lib internal
> usage in the kernel.

Perhaps _tolower should be used a bit more in lib
---
 lib/string.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index ed83562..b0e72fd 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -53,8 +53,8 @@ int strncasecmp(const char *s1, const char *s2, size_t len)
 			break;
 		if (c1 == c2)
 			continue;
-		c1 = tolower(c1);
-		c2 = tolower(c2);
+		c1 = _tolower(c1);
+		c2 = _tolower(c2);
 		if (c1 != c2)
 			break;
 	} while (--len);
@@ -69,8 +69,8 @@ int strcasecmp(const char *s1, const char *s2)
 	int c1, c2;
 
 	do {
-		c1 = tolower(*s1++);
-		c2 = tolower(*s2++);
+		c1 = _tolower(*s1++);
+		c2 = _tolower(*s2++);
 	} while (c1 == c2 && c1 != 0);
 	return c1 - c2;
 }

  reply	other threads:[~2016-06-30 19:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 16:15 [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin zengzhaoxiu
2016-06-29 16:22 ` [PATCH 2/2] lib: kstrtox: _parse_integer: use hex_to_bin instead local conversion, and reduce branches zengzhaoxiu
2016-06-29 22:06   ` Alexey Dobriyan
2016-06-30 14:45     ` Zhaoxiu Zeng
2016-06-29 16:22 ` [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Andy Shevchenko
2016-06-29 16:24 ` Steven Rostedt
2016-06-29 18:31 ` Michal Nazarewicz
2016-06-29 18:52   ` Andy Shevchenko
2016-06-30 19:26     ` Joe Perches [this message]
2016-06-30 19:42       ` Geert Uytterhoeven
2016-06-30 20:06         ` Joe Perches
2016-06-30 20:44           ` Andy Shevchenko
2016-06-30 21:18       ` Michal Nazarewicz
2016-06-30 14:21   ` Zhaoxiu Zeng

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=1467314771.24287.160.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bp@suse.de \
    --cc=geert@linux-m68k.org \
    --cc=gustavo.padovan@collabora.co.uk \
    --cc=hidehiro.kawai.ez@hitachi.com \
    --cc=hmijail@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mhocko@suse.com \
    --cc=mina86@mina86.com \
    --cc=nicolas.iooss_linux@m4x.org \
    --cc=rostedt@goodmis.org \
    --cc=zengzhaoxiu@163.com \
    --cc=zhaoxiu.zeng@gmail.com \
    /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