4x faster strlen with 4 char sentinel

Jay Norwood via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Jun 27 12:51:48 PDT 2016


On Monday, 27 June 2016 at 16:38:58 UTC, Ola Fosheim Grøstad 
wrote:
> Yes, and the idea of speeding up strings by padding out with 
> zeros is not new. ;-) I recall suggesting it back in 1999 when 
> discussing the benefits of having a big endian cpu when sorting 
> strings. If it is big endian you can compare ascii as 32/64 bit 
> integers, so if you align the string and pad out with zeros 
> then you can speed up strcmp() by a significant factor. Oh, 
> here it is:

Your link's use of padding pads out with a variable number of 
zeros, so that a larger data type can be used for the compare 
operations.  This isn't the same as my example, which is simpler 
due to not having to fiddle with alignment and data type casting.

I didn't find a strlen implementation for dchar or wchar in the D 
libraries.

I also found it strange, the non-zero initialization values for 
char, dchar, wchar.  I suppose there's some reason?

int [100]  to zeros.
char [100]  to 0xff;
dchar [100]   to 0xffff;
wchar [100]   to 0xffff;









More information about the Digitalmars-d-announce mailing list