History

avcodec/xbmdec: get_nibble() minor speed increase, and binary reduction

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.

Jose Da Silva committed 5 years ago

Commit 7ccea3b1 parent 8c3d31f1 file · +25 −17Browse files

Unified · Split

libavcodec/xbmdec.c+25−17
@@ -26,15 +26,19 @@ · 25 unmodified lines
2626 #include "internal.h"
2727 #include "mathops.h"
2828
29−static int convert(uint8_t x)
29+static int get_nibble(uint8_t x)
3030 {
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;
3842 }
3943
4044 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
9498 for (i = 0; i < avctx->height; i++) {
9599 dst = p->data[0] + i * p->linesize[0];
96100 for (j = 0; j < linesize; j++) {
97− uint8_t val;
101+ uint8_t nib, val;
98102
99103 while (ptr < end && *ptr != 'x' && *ptr != '$')
100104 ptr++;
101105
102106 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+ }
107113 *dst++ = ff_reverse[val];
108− if (av_isxdigit(*ptr) && j+1 < linesize) {
114+ if ((val = get_nibble(*ptr)) <= 15 && j+1 < linesize) {
109115 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+ }
113121 *dst++ = ff_reverse[val];
114122 }
115123 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t