improved code path for typical platforms where there is a wider integer type
This commit is contained in:
parent
08ba483bfb
commit
baec005507
@ -10,6 +10,16 @@ size_t scan_uint(const char* src,unsigned int* dest) {
|
||||
/* a good optimizing compiler should remove the else clause when not
|
||||
* needed */
|
||||
return scan_ulong(src,(unsigned long*)dest);
|
||||
} else if (sizeof(unsigned int) < sizeof(unsigned long)) {
|
||||
const char* cur;
|
||||
unsigned int l;
|
||||
for (cur=src,l=0; *cur>='0' && *cur<='9'; ++cur) {
|
||||
unsigned long tmp=l*10ul+*cur-'0';
|
||||
if ((unsigned int)tmp != tmp) break;
|
||||
l=tmp;
|
||||
}
|
||||
if (cur>src) *dest=l;
|
||||
return (size_t)(cur-src);
|
||||
} else {
|
||||
register const char *tmp=src;
|
||||
register unsigned int l=0;
|
||||
|
@ -10,6 +10,16 @@ size_t scan_ushort(const char* src,unsigned short* dest) {
|
||||
/* a good optimizing compiler should remove the else clause when not
|
||||
* needed */
|
||||
return scan_uint(src,(unsigned int*)dest);
|
||||
} if (sizeof(unsigned short) < sizeof(unsigned long)) {
|
||||
const char* cur;
|
||||
unsigned short l;
|
||||
for (cur=src,l=0; *cur>='0' && *cur<='9'; ++cur) {
|
||||
unsigned long tmp=l*10ul+*cur-'0';
|
||||
if ((unsigned short)tmp != tmp) break;
|
||||
l=tmp;
|
||||
}
|
||||
if (cur>src) *dest=l;
|
||||
return (size_t)(cur-src);
|
||||
} else {
|
||||
register const char *tmp=src;
|
||||
register unsigned short int l=0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user