String compare performance

"Jérôme M. Berger" jeberger at free.fr
Sun Nov 28 00:26:17 PST 2010


Kagamin wrote:
> You need only match 3-char strings?
> Try this hack
> 
> bool cmp3c(string a, string etalon) pure
> {
>   if(a.length!=3)return false;
>   return *cast(short*)a.ptr==*cast(short*)b.ptr && a[2]==b[2];
> }
	This doesn't work on some architectures if a.ptr or b.ptr is odd...

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101128/8e2d7103/attachment.pgp>


More information about the Digitalmars-d mailing list