mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
small util::base64_decode optimization
This commit is contained in:
parent
3cfdbc8338
commit
ba4338c4fa
1 changed files with 5 additions and 4 deletions
|
|
@ -229,15 +229,16 @@ std::string util::base64_encode(const ubyte* data, size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ubyte> util::base64_decode(const char* str, size_t size) {
|
std::vector<ubyte> util::base64_decode(const char* str, size_t size) {
|
||||||
std::vector<ubyte> bytes;
|
std::vector<ubyte> bytes((size/4)*3);
|
||||||
|
ubyte* dst = bytes.data();
|
||||||
for (size_t i = 0; i < size;) {
|
for (size_t i = 0; i < size;) {
|
||||||
ubyte a = base64_decode_char(ubyte(str[i++]));
|
ubyte a = base64_decode_char(ubyte(str[i++]));
|
||||||
ubyte b = base64_decode_char(ubyte(str[i++]));
|
ubyte b = base64_decode_char(ubyte(str[i++]));
|
||||||
ubyte c = base64_decode_char(ubyte(str[i++]));
|
ubyte c = base64_decode_char(ubyte(str[i++]));
|
||||||
ubyte d = base64_decode_char(ubyte(str[i++]));
|
ubyte d = base64_decode_char(ubyte(str[i++]));
|
||||||
bytes.push_back((a << 2) | ((b & 0b110000) >> 4));
|
*(dst++) = ((a << 2) | ((b & 0b110000) >> 4));
|
||||||
bytes.push_back(((b & 0b1111) << 4) | ((c & 0b111100) >> 2));
|
*(dst++) = (((b & 0b1111) << 4) | ((c & 0b111100) >> 2));
|
||||||
bytes.push_back(((c & 0b11) << 6) | d);
|
*(dst++) = (((c & 0b11) << 6) | d);
|
||||||
}
|
}
|
||||||
if (size >= 2) {
|
if (size >= 2) {
|
||||||
size_t outsize = bytes.size();
|
size_t outsize = bytes.size();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue