Mercurial > dovecot > core-2.2
comparison src/lib/strnum.c @ 22647:641236fac254
lib: str_parse/to_*int*() - minor optimization
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 05 Nov 2017 21:36:55 +0200 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
comparison
equal
deleted
inserted
replaced
22646:340fd327a965 | 22647:641236fac254 |
---|---|
85 uintmax_t n = 0; | 85 uintmax_t n = 0; |
86 | 86 |
87 if (*str < '0' || *str > '9') | 87 if (*str < '0' || *str > '9') |
88 return -1; | 88 return -1; |
89 | 89 |
90 for (; *str >= '0' && *str <= '9'; str++) { | 90 do { |
91 if (n >= ((uintmax_t)-1 / 10)) { | 91 if (n >= ((uintmax_t)-1 / 10)) { |
92 if (n > (uintmax_t)-1 / 10) | 92 if (n > (uintmax_t)-1 / 10) |
93 return -1; | 93 return -1; |
94 if ((uintmax_t)(*str - '0') > ((uintmax_t)-1 % 10)) | 94 if ((uintmax_t)(*str - '0') > ((uintmax_t)-1 % 10)) |
95 return -1; | 95 return -1; |
96 } | 96 } |
97 n = n * 10 + (*str - '0'); | 97 n = n * 10 + (*str - '0'); |
98 } | 98 str++; |
99 } while (*str >= '0' && *str <= '9'); | |
100 | |
99 if (endp_r != NULL) | 101 if (endp_r != NULL) |
100 *endp_r = str; | 102 *endp_r = str; |
101 *num_r = n; | 103 *num_r = n; |
102 return 0; | 104 return 0; |
103 } | 105 } |