Replace av_isxdigit(*ptr) and convert(*ptr) with get_nibble(*ptr) which returns a valid nibble=={0x00..0x0f} or false==255 for all other values. This way we only need to work with *ptr once instead of twice. Removing inline av_isxdigit(x) functions also shrinks executable size.
Unified · Split
| @@ -26,15 +26,19 @@ · 25 unmodified lines | ||
| 26 | 26 | #include "internal.h" |
| 27 | 27 | #include "mathops.h" |
| 28 | 28 | |
| 29 | −static int convert(uint8_t x) | |
| 29 | +static int get_nibble(uint8_t x) | |
| 30 | 30 | { |
| 31 | − if (x <= '9') | |
| 32 | − x -= '0'; | |
| 33 | − else if (x >= 'a') | |
| 34 | − x -= ('a' - 10); | |
| 35 | − else | |
| 36 | − x -= ('A' - 10); | |
| 37 | − return x; | |
| 31 | + int ret = 255; | |
| 32 | + | |
| 33 | + if (x <= '9') { | |
| 34 | + if (x >= '0') | |
| 35 | + ret = x - '0'; | |
| 36 | + } else if (x >= 'a') { | |
| 37 | + if (x <= 'f') | |
| 38 | + ret = x - ('a' - 10); | |
| 39 | + } else if (x >= 'A' && x <= 'F') | |
| 40 | + ret = x - ('A' - 10); | |
| 41 | + return ret; | |
| 38 | 42 | } |
| 39 | 43 | |
| 40 | 44 | static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) |
| @@ -94,22 +98,26 @@ static int xbm_decode_frame(AVCodecContext *avctx, void *data, · 53 unmodified lines | ||
| 94 | 98 | for (i = 0; i < avctx->height; i++) { |
| 95 | 99 | dst = p->data[0] + i * p->linesize[0]; |
| 96 | 100 | for (j = 0; j < linesize; j++) { |
| 97 | − uint8_t val; | |
| 101 | + uint8_t nib, val; | |
| 98 | 102 | |
| 99 | 103 | while (ptr < end && *ptr != 'x' && *ptr != '$') |
| 100 | 104 | ptr++; |
| 101 | 105 | |
| 102 | 106 | ptr ++; |
| 103 | − if (ptr < end && av_isxdigit(*ptr)) { | |
| 104 | − val = convert(*ptr++); | |
| 105 | − if (av_isxdigit(*ptr)) | |
| 106 | − val = (val << 4) + convert(*ptr++); | |
| 107 | + if (ptr < end && (val = get_nibble(*ptr)) <= 15) { | |
| 108 | + ptr++; | |
| 109 | + if ((nib = get_nibble(*ptr)) <= 15) { | |
| 110 | + val = (val << 4) + nib; | |
| 111 | + ptr++; | |
| 112 | + } | |
| 107 | 113 | *dst++ = ff_reverse[val]; |
| 108 | − if (av_isxdigit(*ptr) && j+1 < linesize) { | |
| 114 | + if ((val = get_nibble(*ptr)) <= 15 && j+1 < linesize) { | |
| 109 | 115 | j++; |
| 110 | − val = convert(*ptr++); | |
| 111 | − if (av_isxdigit(*ptr)) | |
| 112 | − val = (val << 4) + convert(*ptr++); | |
| 116 | + ptr++; | |
| 117 | + if ((nib = get_nibble(*ptr)) <= 15) { | |
| 118 | + val = (val << 4) + nib; | |
| 119 | + ptr++; | |
| 120 | + } | |
| 113 | 121 | *dst++ = ff_reverse[val]; |
| 114 | 122 | } |
| 115 | 123 | } else { |