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 | #include "internal.h" | 26 | #include "internal.h" |
| 27 | #include "mathops.h" | 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') | 31 | int ret = 255; |
| 32 | x -= '0'; | 32 | |
| 33 | else if (x >= 'a') | 33 | if (x <= '9') { |
| 34 | x -= ('a' - 10); | 34 | if (x >= '0') |
| 35 | else | 35 | ret = x - '0'; |
| 36 | x -= ('A' - 10); | 36 | } else if (x >= 'a') { |
| 37 | return x; | 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 | static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) | 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 | for (i = 0; i < avctx->height; i++) { | 98 | for (i = 0; i < avctx->height; i++) { |
| 95 | dst = p->data[0] + i * p->linesize[0]; | 99 | dst = p->data[0] + i * p->linesize[0]; |
| 96 | for (j = 0; j < linesize; j++) { | 100 | for (j = 0; j < linesize; j++) { |
| 97 | uint8_t val; | 101 | uint8_t nib, val; |
| 98 | 102 | ||
| 99 | while (ptr < end && *ptr != 'x' && *ptr != '$') | 103 | while (ptr < end && *ptr != 'x' && *ptr != '$') |
| 100 | ptr++; | 104 | ptr++; |
| 101 | 105 | ||
| 102 | ptr ++; | 106 | ptr ++; |
| 103 | if (ptr < end && av_isxdigit(*ptr)) { | 107 | if (ptr < end && (val = get_nibble(*ptr)) <= 15) { |
| 104 | val = convert(*ptr++); | 108 | ptr++; |
| 105 | if (av_isxdigit(*ptr)) | 109 | if ((nib = get_nibble(*ptr)) <= 15) { |
| 106 | val = (val << 4) + convert(*ptr++); | 110 | val = (val << 4) + nib; |
| 111 | ptr++; | ||
| 112 | } | ||
| 107 | *dst++ = ff_reverse[val]; | 113 | *dst++ = ff_reverse[val]; |
| 108 | if (av_isxdigit(*ptr) && j+1 < linesize) { | 114 | if ((val = get_nibble(*ptr)) <= 15 && j+1 < linesize) { |
| 109 | j++; | 115 | j++; |
| 110 | val = convert(*ptr++); | 116 | ptr++; |
| 111 | if (av_isxdigit(*ptr)) | 117 | if ((nib = get_nibble(*ptr)) <= 15) { |
| 112 | val = (val << 4) + convert(*ptr++); | 118 | val = (val << 4) + nib; |
| 119 | ptr++; | ||
| 120 | } | ||
| 113 | *dst++ = ff_reverse[val]; | 121 | *dst++ = ff_reverse[val]; |
| 114 | } | 122 | } |
| 115 | } else { | 123 | } else { |