MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / encode

Function encode

test/benchmark/base64.c:72–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72void encode(int size, const char* str, int* out_size, char** output) {
73 *output = (char*) malloc( encode_size(size) );
74 char *out = *output;
75 const char* ends = str + (size - size % 3);
76 uint n;
77 while (str != ends) {
78 uint32_t n = __builtin_bswap32(*(uint32_t*)str);
79 *out++ = chars[(n >> 26) & 63];
80 *out++ = chars[(n >> 20) & 63];
81 *out++ = chars[(n >> 14) & 63];
82 *out++ = chars[(n >> 8) & 63];
83 str += 3;
84 }
85 int pd = size % 3;
86 if (pd == 1) {
87 n = (uint)*str << 16;
88 *out++ = chars[(n >> 18) & 63];
89 *out++ = chars[(n >> 12) & 63];
90 *out++ = '=';
91 *out++ = '=';
92 } else if (pd == 2) {
93 n = (uint)*str++ << 16;
94 n |= (uint)*str << 8;
95 *out++ = chars[(n >> 18) & 63];
96 *out++ = chars[(n >> 12) & 63];
97 *out++ = chars[(n >> 6) & 63];
98 *out++ = '=';
99 }
100 *out = '\0';
101 *out_size = out - *output;
102}
103
104int main(int argc, char **argv) {
105 int TRIES;

Callers 15

mainFunction · 0.85
encodeMethod · 0.85
set_biased_exponentMethod · 0.85
zeroMethod · 0.85
oneMethod · 0.85
min_subnormalMethod · 0.85
max_subnormalMethod · 0.85
min_normalMethod · 0.85
max_normalMethod · 0.85
infMethod · 0.85
signaling_nanMethod · 0.85
quiet_nanMethod · 0.85

Calls 2

encode_sizeFunction · 0.85
mallocFunction · 0.50

Tested by

no test coverage detected