Some compilers are very intuitive, and others are not so much, so let's pre-compute the variables e and keylen outside the for loop. Ensuring a minor speed increase regardless of if compiler is smart enough to solve this improvement for itself, or not.
Unified · Split
| @@ -39,11 +39,14 @@ static int convert(uint8_t x) · 38 unmodified lines | |||
| 39 | 39 | ||
| 40 | static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) | 40 | static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) |
| 41 | { | 41 | { |
| 42 | for(; p<end - strlen(key); p++) { | 42 | int keylen = strlen(key); |
| 43 | if (!memcmp(p, key, strlen(key))) | 43 | const uint8_t *e = end - keylen; |
| 44 | |||
| 45 | for(; p < e; p++) { | ||
| 46 | if (!memcmp(p, key, keylen)) | ||
| 44 | break; | 47 | break; |
| 45 | } | 48 | } |
| 46 | p += strlen(key); | 49 | p += keylen; |
| 47 | if (p >= end) | 50 | if (p >= end) |
| 48 | return INT_MIN; | 51 | return INT_MIN; |
| 49 | 52 | ||