Re: [PATCH 2/3] speed up Hex2Num
On Sat, Jan 25, 2014 at 03:27:44AM +0100, Jann Horn wrote:
> replaced a call to isxdigit and comparisons with an array lookup
> ---
> apt-pkg/contrib/strutl.cc | 41 ++++++++++++++++++++++++-----------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
> index 9621128..49a2fec 100644
> --- a/apt-pkg/contrib/strutl.cc
> +++ b/apt-pkg/contrib/strutl.cc
> @@ -1047,20 +1047,26 @@ bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len)
> }
> }
> /*}}}*/
> -// HexDigit - Convert a hex character into an integer /*{{{*/
> -// ---------------------------------------------------------------------
> -/* Helper for Hex2Num */
> -static int HexDigit(int c)
> -{
> - if (c >= '0' && c <= '9')
> - return c - '0';
> - if (c >= 'a' && c <= 'f')
> - return c - 'a' + 10;
> - if (c >= 'A' && c <= 'F')
> - return c - 'A' + 10;
> - return 0;
> -}
> - /*}}}*/
> +
> +/* for Hex2Num */
> +static unsigned char hexdigits[256] =
This should be const.
--
Julian Andres Klode - Debian Developer, Ubuntu Member
See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
Please do not top-post if possible.
Reply to: