Browse Source

improved code path for typical platforms where there is a wider integer type

master
Felix von Leitner 8 years ago
parent
commit
f68ede8333
  1. 10
      scan/scan_uint.c
  2. 10
      scan/scan_ushort.c

10
scan/scan_uint.c

@ -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
scan/scan_ushort.c

@ -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…
Cancel
Save