Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-01-21 15:22:19 +0400
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-01-21 17:52:05 +0400
commit523f676b51d8a2eaeb7d75ccdb0258d271430430 (patch)
tree9cbc29c913ed49ffe838f602bf00dc1fc6989f01 /libavutil/base64.c
parentd41c824b233292d7e5314a7029fab8cf554a9b2b (diff)
Use a full table for base64 decode.
Also encodes error or end marker into table. About 20% faster. decode: 466491 -> 374139 decicycles syntax check: 236955 -> 161182 decicycles Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil/base64.c')
-rw-r--r--libavutil/base64.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/libavutil/base64.c b/libavutil/base64.c
index 8d18af125c..6eccd9c9a0 100644
--- a/libavutil/base64.c
+++ b/libavutil/base64.c
@@ -30,32 +30,59 @@
#include "intreadwrite.h"
/* ---------------- private code */
-static const uint8_t map2[] =
+static const uint8_t map2[256] =
{
+ 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff,
+
0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01,
+ 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x01,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
- 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
+ 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
+
+ 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
-int av_base64_decode(uint8_t *out, const char *in, int out_size)
+int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
{
int i, v;
uint8_t *dst = out;
uint8_t *end = out + out_size;
+ // no sign extension
+ const uint8_t *in = in_str;
v = 0;
for (i = 0; ; i++) {
- unsigned int index= in[i]-43;
- if (index>=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff)
- return in[i] && in[i] != '=' ? -1 : dst - out;
- v = (v << 6) + map2[index];
+ unsigned bits = map2[in[i]];
+ if (bits & 0x80)
+ return bits & 1 ? -1 : dst - out;
+ v = (v << 6) + bits;
if (i & 3) {
if (dst < end) {
*dst++ = v >> (6 - 2 * (i & 3));