lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thank you everyone for the suggestions.
Pre-loading the hex values is indeed a good idea.
The fastest Lua version by Patrick seems to be fast enough.

I've been considering a C impl indeed. 

If the workload will suddenly increase, I'll surely use implement a C version of it.

best regards,
valerio

On Sat, Apr 17, 2010 at 5:18 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
* Michal Kottman:

> Another (faster) alternative is to avoid the sprintf() call and
> calculate hex string directly:
>
> static char hex[] = "0123456789ABCDEF";
>
> ...
>
>   for ( p = ns , max = size ; max > 0 ; max--)
>   {
> *p++ = hex[*s >> 4];
> *p++ = hex[*s++ & 0xF];
>   }

Caution: this doesn't work with signed chars, you have to change s to
a pointer to an unsigned char in Sean's code.