Minor speed increase, end is calculated before entering parse_str_int(), so let's take advantage of the value and avoid recalculating twice more. This also allows parse_str_int() to work with file size larger than int.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -37,10 +37,8 @@ static int convert(uint8_t x) · 36 unmodified lines | ||
| 37 | 37 | return x; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | −static int parse_str_int(const uint8_t *p, int len, 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 | − const uint8_t *end = p + len; | |
| 43 | − | |
| 44 | 42 | for(; p<end - strlen(key); p++) { |
| 45 | 43 | if (!memcmp(p, key, strlen(key))) |
| 46 | 44 | break; |
| @@ -72,8 +70,8 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data, · 25 unmodified lines | ||
| 72 | 70 | avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; |
| 73 | 71 | end = avpkt->data + avpkt->size; |
| 74 | 72 | |
| 75 | − width = parse_str_int(avpkt->data, avpkt->size, "_width"); | |
| 76 | − height = parse_str_int(avpkt->data, avpkt->size, "_height"); | |
| 73 | + width = parse_str_int(avpkt->data, end, "_width"); | |
| 74 | + height = parse_str_int(avpkt->data, end, "_height"); | |
| 77 | 75 | |
| 78 | 76 | if ((ret = ff_set_dimensions(avctx, width, height)) < 0) |
| 79 | 77 | return ret; |