base64: provide a fast path for encoding well sized buffers
authorPádraig Brady <P@draigBrady.com>
Mon, 11 Nov 2013 14:19:09 +0000 (14:19 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 11 Nov 2013 23:07:11 +0000 (23:07 +0000)
commit43fd1e7b5a01623bc59fcf68254ce5be8e0b8d42
tree5bc367bb2d4a41075e188e49f6eb57634ce3ffa1
parentcdceb2fe48e39f4fff25f6f4cb34bbab88c2856f
base64: provide a fast path for encoding well sized buffers

Avoid conditionals in the base64 encoding loop,
which was seen to give a 60% throughput improvement
with the base64 utility from coreutils:

$ truncate -s100MiB file.in
$ time base64-old -w0 < file.in >/dev/null
real  0m0.302s
$ time base64-new -w0 < file.in >/dev/null
real  0m0.182s

* lib/base64.c (base64_encode_fast): A new function to be called
when we don't want to NUL terminate, and we have enough space
in the output to encode the given input.
(base64_encode): Call the _fast() version when appropriate.
Also remove a redundant mask with 0x3F on the first encoded byte.
ChangeLog
lib/base64.c