From: Andrew Morton <akpm@linux-foundation.org>
To: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/10] lib: introduce common method to convert hex digits
Date: Fri, 30 Apr 2010 12:07:03 -0700 [thread overview]
Message-ID: <20100430120703.ffab0258.akpm@linux-foundation.org> (raw)
In-Reply-To: <d5c4e26cc74458dd77102c4274d3260149717328.1272617852.git.ext-andriy.shevchenko@nokia.com>
On Fri, 30 Apr 2010 12:34:00 +0300
Andy Shevchenko <ext-andriy.shevchenko@nokia.com> wrote:
> /**
> + * hex_to_bin - convert a hex digit to its real value
> + * @ch: ascii character represents hex digit
> + *
> + * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
> + * input.
> + */
> +int hex_to_bin(char ch)
> +{
> + if ((ch >= 'a') && (ch <= 'f'))
> + return ch - 'a' + 10;
> + if ((ch >= '0') && (ch <= '9'))
> + return ch - '0';
> + if ((ch >= 'A') && (ch <= 'F'))
> + return ch - 'A' + 10;
> + return -1;
> +}
> +EXPORT_SYMBOL(hex_to_bin);
I had to fiddle with it:
- use tolower(), saving 3 bytes!
- test the more common case first - it's quicker.
diff -puN lib/hexdump.c~lib-introduce-common-method-to-convert-hex-digits-fix lib/hexdump.c
--- a/lib/hexdump.c~lib-introduce-common-method-to-convert-hex-digits-fix
+++ a/lib/hexdump.c
@@ -24,12 +24,11 @@ EXPORT_SYMBOL(hex_asc);
*/
int hex_to_bin(char ch)
{
- if ((ch >= 'a') && (ch <= 'f'))
- return ch - 'a' + 10;
+ ch = tolower(ch);
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
- if ((ch >= 'A') && (ch <= 'F'))
- return ch - 'A' + 10;
+ if ((ch >= 'a') && (ch <= 'f'))
+ return ch - 'a' + 10;
return -1;
}
EXPORT_SYMBOL(hex_to_bin);
_
Yielding
int hex_to_bin(char ch)
{
ch = tolower(ch);
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
return -1;
}
next prev parent reply other threads:[~2010-04-30 19:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-30 9:33 [PATCH 00/10] Introduce common hex_to_bin() helper Andy Shevchenko
2010-04-30 9:34 ` [PATCH 01/10] lib: introduce common method to convert hex digits Andy Shevchenko
2010-04-30 19:07 ` Andrew Morton [this message]
2010-05-01 2:55 ` Joe Perches
2010-05-02 18:12 ` Andy Shevchenko
2010-04-30 9:34 ` [PATCH 02/10] drivers: isdn: use new hex_to_bin() method Andy Shevchenko
2010-04-30 9:34 ` [PATCH 03/10] usb: atm: speedtch: " Andy Shevchenko
2010-04-30 9:34 ` [PATCH 04/10] drivers: net: " Andy Shevchenko
2010-04-30 9:34 ` [PATCH 05/10] " Andy Shevchenko
2010-05-04 0:14 ` Divy Le Ray
2010-04-30 9:34 ` [PATCH 06/10] sysctl: don't use own implementation of hex_to_bin() Andy Shevchenko
2010-04-30 9:34 ` [PATCH 07/10] staging: rt2860: use new hex_to_bin() method Andy Shevchenko
2010-04-30 9:34 ` [PATCH 08/10] fs: ldm: don't use own implementation of hex_to_bin() Andy Shevchenko
2010-04-30 9:34 ` [PATCH 09/10] drivers: wireless: use new hex_to_bin() method Andy Shevchenko
2010-04-30 18:14 ` John W. Linville
2010-04-30 9:34 ` [PATCH 10/10] drivers: acpi: don't use own implementation of hex_to_bin() Andy Shevchenko
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=20100430120703.ffab0258.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=ext-andriy.shevchenko@nokia.com \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.