[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: |
Pádraig Brady |
Subject: |
Re: [PATCH] base64: provide a fast path for encoding well sized buffers |
Date: |
Mon, 11 Nov 2013 19:36:08 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 11/11/2013 06:37 PM, Paul Eggert wrote:
> 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.
Moved to module scope.
>> + 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.
Ah right, reduce outlen to match inlen.
thanks!
Pádraig.