Skip to content

Commit

Permalink
fixup! sys/fmt: optimize scn_u32_dec scn_u32_hex
Browse files Browse the repository at this point in the history
  • Loading branch information
kfessel committed Dec 8, 2022
1 parent 3d7ae26 commit f6a759d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sys/fmt/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ uint32_t scn_u32_dec(const char *str, size_t n)
uint32_t res = 0;

while (n--) {
unsigned char c = *str++;
unsigned d = c - '0';
if ( d > 9 ) {
unsigned c = *str++;
unsigned d = c - (unsigned)'0';
if ( !( '0'<= c && c <= '9') ) {
break;
}
res *= 10;
res *= 10U;
res += d;
}
return res;
Expand All @@ -486,15 +486,15 @@ uint32_t scn_u32_hex(const char *str, size_t n)
uint32_t res = 0;

while (n--) {
unsigned char c = *str++;
unsigned c = *str++;
unsigned d;
if ( c - '0' <= 9 ) {
if ( '0'<= c && c <= '9'){
d = c - '0';
}
else if ( c - 'A' <= 'F' - 'A' ) {
else if ( 'A' <= c && c <= 'F' ) {
d = c - 'A' + 0xa;
}
else if ( c - 'a' <= 'f' - 'a' ) {
else if ( 'a' <= c && c <= 'f' ) {
d = c - 'a' + 0xa;
}
else {
Expand Down

0 comments on commit f6a759d

Please sign in to comment.