1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-20 02:42:09 +03:00

base64: do not use snprintf() on encoding

This also significantly (by 7-8x in my limited tests with a short
string) speeds up this function. The impact is still minor as this
function is only used in `knownhost.c` in release builds.

Closes #985
This commit is contained in:
Viktor Szakats
2023-04-19 18:22:53 +00:00
parent 6c01fa5bb7
commit 8d10b21731

View File

@@ -443,22 +443,22 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
switch(inputparts) { switch(inputparts) {
case 1: /* only one byte read */ case 1: /* only one byte read */
snprintf(output, 5, "%c%c==", output[0] = table64[obuf[0]];
table64[obuf[0]], output[1] = table64[obuf[1]];
table64[obuf[1]]); output[2] = '=';
output[3] = '=';
break; break;
case 2: /* two bytes read */ case 2: /* two bytes read */
snprintf(output, 5, "%c%c%c=", output[0] = table64[obuf[0]];
table64[obuf[0]], output[1] = table64[obuf[1]];
table64[obuf[1]], output[2] = table64[obuf[2]];
table64[obuf[2]]); output[3] = '=';
break; break;
default: default:
snprintf(output, 5, "%c%c%c%c", output[0] = table64[obuf[0]];
table64[obuf[0]], output[1] = table64[obuf[1]];
table64[obuf[1]], output[2] = table64[obuf[2]];
table64[obuf[2]], output[3] = table64[obuf[3]];
table64[obuf[3]]);
break; break;
} }
output += 4; output += 4;