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.
This commit is contained in:
parent
444e318434
commit
c7dafd4acd
|
@ -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 @@ _FUNCNAME(const char *nptr, char **endptr, int base)
|
|||
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)
|
||||
|
|
|
@ -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 @@ _FUNCNAME(const char *nptr, char **endptr, int base)
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue