curl-library
Re: [PATCH] rawstr: Speed up Curl_raw_toupper by 40%
Date: Thu, 5 Nov 2015 17:03:36 +0100
It find that the gain is strange, because such a code :
> - switch (in) {
> - case 'a':
> - return 'A';
...is turned at compile time, into calls via a virtual function table as
return f[in]();
where the functions are something like
char f[a]() { return 'A'; }
char f[b]() { return 'B'; }
An explanation for the performance gain is that the new code could be
inlined ?
You know, I prefer to deal with something similar, build a table at start:
char maj[] = { 'A', 'B', ... 'Z' };
then in the function, return maj[(unsigned char) (in-'a')]
I'm not sure that this is better than the new Curl_raw_toupper code but
try with a 256-elements table : it now avoids the "if (in >= 'a' && in
<= 'z')" test, and the addition/subtraction too !
I mean:
char Curl_raw_toupper(char in) { return maj[(unsigned char) in]; }
Seems good ? I never did benchmarks on this...
ChD
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-11-05