Closed Bug 132679 Opened 24 years ago Closed 17 years ago

optimize nsString::Equals* to be faster than Compare()

Categories

(Core :: XPCOM, defect, P2)

x86
Windows 2000
defect

Tracking

()

RESOLVED INCOMPLETE
mozilla1.5alpha

People

(Reporter: alecf, Assigned: alecf)

References

Details

(Keywords: perf)

Ok, I've been wallowing around in nsStr*.cpp, and watching calls to StrCompare2To1 and friends.. and basically I've decided we really need to optimize nsString::Equals and friends (nsString::EqualsIgnoreCase, etc) 1) We need to make it check for length before any kind of comparison, so that if lengths are unequal, then we immediately stop and proclaim the strings unequal 2) we need EqualsIgnoreCase to accept nsAFlatString&'s so that people can pass in strings with length. I'm seeing literally hundreds (if not thousands) of string comparisons like this in CSS: if (str.EqualsIgnoreCase("inherit"))... which would be greatly sped up by accepting nsAFlatStrings, and replacing this with if (str.EqualsIgnoreCase(NS_LITERAL_CSTRING("inherit"))... I have no idea what kind of performance benefit this would have, but I sure see a lot of calls to Compare2to1 :)
Status: NEW → ASSIGNED
Keywords: perf
doesn't nsString::Equals already check the length? (nsAString::Equals certainly does). Also, do we want to just change nsString::EqualsIgnoreCase? Or also to convert those calls to use plain old Equals() with a comparator (that would involve putting NS_LITERAL_STRING all over and paying the memory penalty (on Windows/Mac), unfortunately).
nah, in this case I think its better to have EqualsIgnoreCase - we don't want to call into the intl libraries just to see if a string matches "inherit" or something ascii-like like that. I'm moving this out to moz1.1 for now because I'm pretty darn busy right now... however in my tree I have conversion of much of nsStr*.cpp over to nsAFlatString, which makes the EqualsIgnoreCase(const nsAFlatString& ) a whole lot easier. (and no, I didn't convert to nsASingleFragmentString..because it doesn't have .get() or a similarly easy way to grab a pointer to the front of the fragment)
Priority: -- → P2
Target Milestone: --- → mozilla1.1alpha
> (and no, I didn't convert to nsASingleFragmentString..because it doesn't have > .get() or a similarly easy way to grab a pointer to the front of the fragment) const PRUnichar* begin; myASingleFragmentString.BeginReading(begin);
Yes, I know :) My issue is that I've got about a million lines like StrCompare(foo.mStr, bar.mUStr, ...); etc or even more annoying if (blah(foo.mStr,..)) { if (compare(bar.mStr...)) { } else if (compare(bar.mUStr, ...)) etc what I'm getting at is I'd like a functional (as in lisp) way of getting to this. Maybe I'll write an inline helper routine...
Target Milestone: mozilla1.1alpha → mozilla1.2alpha
woah, 1.1 came up quick. Throwing these bugs over to 1.2.. little or no work has been done and there is no way that these bugs can be fixed in 1.1.
Depends on: 156713
pushing out to mozilla 1.3alpha for now. I might come back to this, or it might just get fixed when I fix bug 156713
Target Milestone: mozilla1.2alpha → mozilla1.3alpha
moving non-critical 1.3alpha bugs to 1.4alpha
Target Milestone: mozilla1.3alpha → mozilla1.4alpha
mass moving lower risk 1.4alpha stuff to 1.4beta
Target Milestone: mozilla1.4alpha → mozilla1.4beta
Target Milestone: mozilla1.4beta → mozilla1.5alpha
QA Contact: jag → string
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → INCOMPLETE
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.