Closed Bug 225887 Opened 22 years ago Closed 22 years ago

trivial optimization in nsCharTraits.h

Categories

(Core :: XPCOM, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: dwitte, Assigned: dwitte)

References

Details

Attachments

(2 files)

http://lxr.mozilla.org/seamonkey/source/xpcom/string/public/nsCharTraits.h#175 there's no need for two |if| tests... we can just return the difference if the two chars aren't equal. we use memcmp elsewhere in nsCharTraits, whose return values aren't restricted to {-1,0,1}... so this optimization is unlikely to cause a problem.
Attached patch fixSplinter Review
Attachment #135653 - Flags: superreview?(alecf)
Attachment #135653 - Flags: review?(jag)
Comment on attachment 135653 [details] [diff] [review] fix yay! less branching. sr=alecf
Comment on attachment 135653 [details] [diff] [review] fix yay! less branching. sr=alecf
Attachment #135653 - Flags: superreview?(alecf) → superreview+
Comment on attachment 135653 [details] [diff] [review] fix Why not simply: #else return to_int_type(*s1 - *s2); #endif
we want to compare the whole string, right? (sorry about lack of context in the diff, see lxr link in comment 0)
Comment on attachment 135653 [details] [diff] [review] fix Duh, the for loop was enough context. pebcak (it was too early in the morning to review). r=jag
Attachment #135653 - Flags: review?(jag) → review+
np :) fixed.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Whoa, this isn't right. to_int_type does an intermediate cast to PRUint16, so the resulting code is similar to: return int((unsigned short)(*s1 - *s2)); which returns 65535 for *s1 = 'a', *s2 = 'b'. This broke sorting in the Linux filepicker and probably other places.
right - i actually suspected that might be a problem, and tested it before i landed. my testing showed it was fine, so maybe i made a mistake when testing... sigh :/ thanks for the report. patch coming up.
Attached patch le fixSplinter Review
Comment on attachment 135987 [details] [diff] [review] le fix this look ok, alecf?
Attachment #135987 - Flags: superreview?(alecf)
Attachment #135987 - Flags: review?(alecf)
Comment on attachment 135987 [details] [diff] [review] le fix oh, duh :) sr=alecf
Attachment #135987 - Flags: superreview?(alecf) → superreview+
*** Bug 226310 has been marked as a duplicate of this bug. ***
Attachment #135987 - Flags: review?(alecf) → review+
Attachment #135987 - Flags: approval1.6b?
Attachment #135987 - Flags: approval1.6b? → approval1.6b+
checked in.
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: