[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] base64: provide a fast path for encoding well sized buffers
From: |
Paul Eggert |
Subject: |
Re: [PATCH] base64: provide a fast path for encoding well sized buffers |
Date: |
Mon, 11 Nov 2013 10:37:21 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
Pádraig Brady wrote:
> + static const char b64c[64] =
> + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
...
> + static const char b64c[64] =
> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
There only needs to be one copy of b64c.
> + if ((inlen % 3 == 0) && BASE64_LENGTH (inlen) == outlen)
This divides by 3 twice, once for % and once for BASE64_LENGTH,
and if we want to be truly paranoid it can mess up due to overflow,
e.g., on a 32-bit host if inlen == 2**32 - 1 && outlen == 0.
How about this instead?
if (outlen % 4 == 0 && inlen == outlen / 4 * 3)
where any decent compiler should do the right thing and
generate only shifts, masks, and adds; and there's no
problem with overflow.