Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc/stdlib Do not use isalpha here, since we exp...



details:   https://anonhg.NetBSD.org/src/rev/9cf1521b33fc
branches:  trunk
changeset: 786133:9cf1521b33fc
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Apr 16 19:34:57 2013 +0000

description:
Do not use isalpha here, since we explicitly only support the Portable
Character Set as base and in theory a locale could define a ASCII
control character as letter, resulting in negations. Also avoid isdigit
here to give the compiler a better chance of deciding whether an
unsigned compare or a jump table is a better option, both are very
likely better choices than the memory indirection.

diffstat:

 common/lib/libc/stdlib/_strtol.h  |  10 ++++++----
 common/lib/libc/stdlib/_strtoul.h |  10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diffs (50 lines):

diff -r 945b0ed3bd73 -r 9cf1521b33fc common/lib/libc/stdlib/_strtol.h
--- a/common/lib/libc/stdlib/_strtol.h  Tue Apr 16 16:52:13 2013 +0000
+++ b/common/lib/libc/stdlib/_strtol.h  Tue Apr 16 19:34:57 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtol.h,v 1.3 2012/03/09 15:41:16 christos Exp $ */
+/* $NetBSD: _strtol.h,v 1.4 2013/04/16 19:34:57 joerg Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -120,10 +120,12 @@
                cutlim = -cutlim;
        }
        for (acc = 0, any = 0;; c = *s++) {
-               if (isdigit(c))
+               if (c >= '0' && c <= '9')
                        i = c - '0';
-               else if (isalpha(c))
-                       i = c - (isupper(c) ? 'A' - 10 : 'a' - 10);
+               else if (c >= 'a' && c <= 'z')
+                       i = (c - 'a') + 10;
+               else if (c >= 'A' && c <= 'Z')
+                       i = (c - 'A') + 10;
                else
                        break;
                if (i >= base)
diff -r 945b0ed3bd73 -r 9cf1521b33fc common/lib/libc/stdlib/_strtoul.h
--- a/common/lib/libc/stdlib/_strtoul.h Tue Apr 16 16:52:13 2013 +0000
+++ b/common/lib/libc/stdlib/_strtoul.h Tue Apr 16 19:34:57 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtoul.h,v 1.3 2012/03/22 15:57:29 christos Exp $ */
+/* $NetBSD: _strtoul.h,v 1.4 2013/04/16 19:34:58 joerg Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -94,10 +94,12 @@
        cutoff = ((__UINT)__UINT_MAX / (__UINT)base);
        cutlim = (int)((__UINT)__UINT_MAX % (__UINT)base);
        for (acc = 0, any = 0;; c = *s++) {
-               if (isdigit(c))
+               if (c >= '0' && c <= '9')
                        i = c - '0';
-               else if (isalpha(c))
-                       i = c - (isupper(c) ? 'A' - 10 : 'a' - 10);
+               else if (c >= 'a' && c <= 'z')
+                       i = (c - 'a') + 10;
+               else if (c >= 'A' && c <= 'Z')
+                       i = (c - 'A') + 10;
                else
                        break;
                if (i >= base)



Home | Main Index | Thread Index | Old Index