This makes the code 2-3 times as fast
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -27,6 +27,7 @@ |
| 27 | 27 |
#include "common.h" |
| 28 | 28 |
#include "base64.h" |
| 29 | 29 |
#include "avassert.h" |
| 30 |
+#include "intreadwrite.h" |
|
| 30 | 31 |
|
| 31 | 32 |
/* ---------------- private code */ |
| 32 | 33 |
static const uint8_t map2[] = |
| ... | ... |
@@ -85,6 +86,15 @@ char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size) |
| 85 | 85 |
out_size < AV_BASE64_SIZE(in_size)) |
| 86 | 86 |
return NULL; |
| 87 | 87 |
ret = dst = out; |
| 88 |
+ while (bytes_remaining > 3) {
|
|
| 89 |
+ i_bits = AV_RB32(in); |
|
| 90 |
+ in += 3; bytes_remaining -= 3; |
|
| 91 |
+ *dst++ = b64[ i_bits>>26 ]; |
|
| 92 |
+ *dst++ = b64[(i_bits>>20) & 0x3F]; |
|
| 93 |
+ *dst++ = b64[(i_bits>>14) & 0x3F]; |
|
| 94 |
+ *dst++ = b64[(i_bits>>8 ) & 0x3F]; |
|
| 95 |
+ } |
|
| 96 |
+ i_bits = 0; |
|
| 88 | 97 |
while (bytes_remaining) {
|
| 89 | 98 |
i_bits = (i_bits << 8) + *in++; |
| 90 | 99 |
bytes_remaining--; |