Re: Most important QC of the year
- From: "Pierre le Riche" <pleriche@xxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 22:29:40 +0200
Hi Roddy,
I don't think this will actually make *significant* improvements in
most cases. The odds on your strings having different lengths are
probably similar to the odds on the first characters being different,
so any real-world gain is likley to come from the 'tighter' code which
the fastcode guys write...
You raise an interesting point. The suggested LStrCmp is somewhat faster
than _LStrEqual when the string lengths are the same but the first character
differs (LStrEqual does an extra two memory reads and a stack push/pop in
this case). In all other cases _LStrEqual is significantly faster,
especially when the string lengths differ and the first character is the
same (like what could occur often when you're scanning a sorted list) - then
it just blows _LStrCmp out the water.
I did toy with the idea of adding the first character comparison to
_LStrEqual as well, but with the data I tested with it didn't seem to help.
The cost of setting up the comparison loop of _LStrCmp outweighs the cost of
the possible branch mispredict when comparing the first character, but in
_LStrEqual the loop setup is much cheaper so that is probably why _LStrEqual
didn't seem to benefit from it. I do reserve the right to go back and add
that check though ;-).
You might also wonder why it initially only compares the first character and
not the first two (long strings are zero terminated after all, so it should
be safe to read two characters): Unfortunately there are third party
libraries that generate non-nil pointer strings of 0 length. The rules
regarding this is somewhat vague, since the RTL functions never generate
such strings itself but it does function correctly with them (except for the
compiler magic "if AString = ' then" type checks which returns false for
such strings).
Regards,
Pierre
.
- Prev by Date: Re: Borland set to sell IDE business
- Next by Date: Re: Borland set to sell IDE business
- Previous by thread: Re: Most important QC of the year
- Next by thread: Re: Most important QC of the year
- Index(es):
Relevant Pages
|