toUTFz and WinAPI GetTextExtentPoint32W
Christophe Travert
travert at phare.normalesup.org
Wed Sep 21 10:12:50 PDT 2011
> Here is a more readable and a bit faster version on dmd windows:
>
> size_t utfCount(string text)
> {
> size_t n = 0;
> for (uint i=0; i<text.length; ++i)
> n += ((text[i]>>6)^0b10)? 1: 0;
> return n;
> }
Nice. It is better with gdc linux 64bits too. I wanted to avoid
conditional expressions like ?: but it's actually slightly faster that
way.
And now people can't tell it is dangerous because it could return a
fuzzy number.
Even faster, through less readable:
size_t utfLength(string text)
{
size_t n=0;
for (size_t i=0; i<text.length; ++i)
n += (((text[i]>>6)^0b10) != 0);
return n;
}
Let's see how we can boost std.utf.stride that way...
--
Christophe
More information about the Digitalmars-d-learn
mailing list