avcodec/xbmdec: Use LUT for hex char->number conversion

Improves performance by about 30%.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
release/7.0
Andreas Rheinhardt 12 months ago
parent 8fb89790af
commit 0b2ed7f6c7
  1. 27
      libavcodec/xbmdec.c

@ -28,17 +28,22 @@
static int get_nibble(uint8_t x) static int get_nibble(uint8_t x)
{ {
int ret = 255; #define TIMES256(idx) \
TIMES64(4 * (idx)) TIMES64(4 * (idx) + 1) TIMES64(4 * (idx) + 2) TIMES64(4 * (idx) + 3)
if (x <= '9') { #define TIMES64(idx) \
if (x >= '0') TIMES16(4 * (idx)) TIMES16(4 * (idx) + 1) TIMES16(4 * (idx) + 2) TIMES16(4 * (idx) + 3)
ret = x - '0'; #define TIMES16(idx) \
} else if (x >= 'a') { TIMES4(4 * (idx)) TIMES4(4 * (idx) + 1) TIMES4(4 * (idx) + 2) TIMES4(4 * (idx) + 3)
if (x <= 'f') #define TIMES4(idx) \
ret = x - ('a' - 10); ENTRY(4 * (idx)) ENTRY(4 * (idx) + 1) ENTRY(4 * (idx) + 2) ENTRY(4 * (idx) + 3)
} else if (x >= 'A' && x <= 'F') #define ENTRY(x) [x] = ((x) >= 'a' && (x) <= 'f') ? (x) - ('a' - 10) : \
ret = x - ('A' - 10); ((x) >= 'A' && (x) <= 'F') ? (x) - ('A' - 10) : \
return ret; ((x) >= '0' && (x) <= '9') ? (x) - '0' : 255,
static const uint8_t lut[] = {
TIMES256(0)
};
return lut[x];
} }
static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key) static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key)

Loading…
Cancel
Save