digitalmars.D - Re: String compare performance
- Kagamin <spam here.lot> Nov 27 2010
- Kagamin <spam here.lot> Nov 27 2010
- bearophile <bearophileHUGS lycos.com> Nov 27 2010
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> Nov 28 2010
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]; }
Nov 27 2010
or bool cmp3c(string a, string b) pure { if(a.length!=3)return false; return *cast(char[3]*)a.ptr==*cast(char[3]*)b.ptr; } llvm.memcmp should rock with lengths known at compile time.
Nov 27 2010
Kagamin:You need only match 3-char strings? Try this hack
I agree there are are ways to speed up the code, probably the D #3 code is fast enough. But while some things are better left to Phobos, comparing short strings efficiently is the compiler's job, not mine (and I am not sure your trick works in C99). Bye, bearophile
Nov 27 2010
Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Kagamin wrote:You need only match 3-char strings? Try this hack =20 bool cmp3c(string a, string etalon) pure { if(a.length!=3D3)return false; return *cast(short*)a.ptr=3D=3D*cast(short*)b.ptr && a[2]=3D=3Db[2]; }
Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Nov 28 2010