Closed Bug 67577 Opened 24 years ago Closed 24 years ago

basic_nsAReadableString<CharT>::Equals should short circuit

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla0.9

People

(Reporter: jband_mozilla, Assigned: scc)

References

Details

I think the template method... PRBool basic_nsAReadableString<CharT>::Equals( const basic_nsAReadableString<CharT>& rhs ) const ...should short-circuit when Length() != rhs.Length(). This might often avoid lots of unnecessary groveling through the chars in Compare. In cases where the lengths are equal the cost of this check is a duplicated pair of Length() calls - since ::Compare will itself still need to do this. I have no numbers to show this as a win, only my guess. Do with it what you will :)
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9
Here's a patch --- Index: mozilla/string/public/nsAReadableString.h =================================================================== RCS file: /cvsroot/mozilla/string/public/nsAReadableString.h,v retrieving revision 1.93 diff -u -2 -r1.93 nsAReadableString.h --- nsAReadableString.h 2001/02/07 03:04:46 1.93 +++ nsAReadableString.h 2001/02/23 00:50:01 @@ -516,5 +516,5 @@ basic_nsAReadableString<CharT>::Equals( const basic_nsAReadableString<CharT>& rhs ) const { - return Compare(rhs) == 0; + return Length() == rhs.Length() && Compare(rhs) == 0; }
Keywords: approval, patch, review
r=jag
sr=hyatt
fix checked in, thanks guys. Hope this makes you happy, jband.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Blocks: 70090
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.