Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1434803

Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin

From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin
Date 2016-06-30 21:30 +0200
Message-ID <rPPOV-55J-13@gated-at.bofh.it> (permalink)
References <rPqxb-6tq-5@gated-at.bofh.it> <rPsyZ-7FB-27@gated-at.bofh.it> <rPsSl-7My-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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;
 }

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin zengzhaoxiu@163.com - 2016-06-29 18:30 +0200
  Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-06-29 18:30 +0200
  Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Michal Nazarewicz <mina86@mina86.com> - 2016-06-29 20:40 +0200
    Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-06-29 21:00 +0200
      Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Joe Perches <joe@perches.com> - 2016-06-30 21:30 +0200
        Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Geert Uytterhoeven <geert@linux-m68k.org> - 2016-06-30 21:50 +0200
          Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Joe Perches <joe@perches.com> - 2016-06-30 22:10 +0200
            Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-06-30 22:50 +0200
        Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Michal Nazarewicz <mina86@mina86.com> - 2016-06-30 23:20 +0200
    Re: [PATCH 1/2] lib: hexdump: use a look-up table to do hex_to_bin Zhaoxiu Zeng <zengzhaoxiu@163.com> - 2016-06-30 16:30 +0200

csiph-web