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
26#include "internal.h"26#include "internal.h"
27#include "mathops.h"27#include "mathops.h"
28 28
29static int convert(uint8_t x)29static 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 else35 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
40static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key)44static 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 {

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