Open
Bug 791546
Opened 12 years ago
Updated 2 years ago
Remove nsCRT::strcmp(const PRUnichar* s) from nsCRT.h
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
NEW
People
(Reporter: kshriram18, Unassigned)
References
(Blocks 1 open bug, )
Details
(Keywords: perf, Whiteboard: [patchlove])
Attachments
(1 file, 5 obsolete files)
(deleted),
patch
|
kshriram18
:
review+
|
Details | Diff | Splinter Review |
nsCRT::strcmp(const PRUnichar* s) will be replaced with NS_strcmp @
http://dxr.lanedo.com/mozilla-central/xpcom/glue/nsCRTGlue.h.html#l50
Comment 1•12 years ago
|
||
Why is NS_strcmp faster than the compiler's strcmp?
Reporter | ||
Comment 2•12 years ago
|
||
(In reply to Marco Castelluccio [:marco] from comment #1)
> Why is NS_strcmp faster than the compiler's strcmp?
Less # of comparisons i.e, double check
http://dxr.lanedo.com/mozilla-central/xpcom/ds/nsCRT.cpp.html#l93
especially when strings match will help.
For reference, NS_strcmp:
http://dxr.lanedo.com/mozilla-central/xpcom/glue/nsCRTGlue.cpp.html#l81
Also, comment @
https://bugzilla.mozilla.org/show_bug.cgi?id=786687#c2
Comment 3•12 years ago
|
||
(In reply to Shriram (irc: Mavericks) from comment #2)
> Less # of comparisons i.e, double check
Oh, ok. I didn't see you wanted to remove only the PRUnichar function.
Maybe you can remove the null check in http://dxr.lanedo.com/mozilla-central/nsprpub/lib/libc/src/strcmp.c.html#l10 too.
Reporter | ||
Comment 4•12 years ago
|
||
(In reply to Marco Castelluccio [:marco] from comment #3)
> Maybe you can remove the null check in
> http://dxr.lanedo.com/mozilla-central/nsprpub/lib/libc/src/strcmp.c.html#l10
> too.
I agree. I was thinking about that.
May be another bug needs to be filed for it.
So,
PL_strcmp can just be
{
return (PRIntn)strcmp(a,b);
}
I looked at removing the const char* function too. It uses PL_strcmp
http://dxr.lanedo.com/mozilla-central/xpcom/ds/nsCRT.h.html#l76
Instead of a function call to PL_strcmp, can we replace it with strcmp(s1, s2) directly ? May be that could help
Reporter | ||
Comment 5•12 years ago
|
||
Attachment #668991 -
Flags: review?(doug.turner)
Attachment #668991 -
Flags: feedback?(doug.turner)
Reporter | ||
Comment 6•12 years ago
|
||
Attachment #668991 -
Attachment is obsolete: true
Attachment #668991 -
Flags: review?(doug.turner)
Attachment #668991 -
Flags: feedback?(doug.turner)
Attachment #669113 -
Flags: review?(doug.turner)
Attachment #669113 -
Flags: feedback?(doug.turner)
Updated•12 years ago
|
Attachment #669113 -
Flags: review?(doug.turner)
Attachment #669113 -
Flags: review?(benjamin)
Attachment #669113 -
Flags: feedback?(doug.turner)
Comment 7•12 years ago
|
||
Comment on attachment 669113 [details] [diff] [review]
Patch that removes function nsCRT::strcmp(const PRUnichar *) and replaces it with NS_strcmp
As with the other bug, NS_strcmp is not null-safe. Did you check the callsites to make sure null is never possible?
Updated•12 years ago
|
Attachment #669113 -
Flags: review?(benjamin)
Reporter | ||
Comment 8•12 years ago
|
||
This patch removes some changes that belong to a patch for another bug
Attachment #669113 -
Attachment is obsolete: true
Reporter | ||
Comment 9•12 years ago
|
||
Checked the calls sites for null
Attachment #689687 -
Attachment is obsolete: true
Attachment #691698 -
Flags: review?(benjamin)
Comment 10•12 years ago
|
||
Comment on attachment 691698 [details] [diff] [review]
Patch that removes function nsCRT::strcmp(const PRUnichar *) and replaces it with NS_strcmp
>--- a/intl/locale/src/nsLocale.cpp
> int
> nsLocale::Hash_CompareNSString(const void* s1, const void* s2)
> {
>- return !nsCRT::strcmp((const PRUnichar *) s1, (const PRUnichar *) s2);
>+ if (s1 && s2) {
>+ return !NS_strcmp((const PRUnichar *) s1, (const PRUnichar *) s2);
>+ }
>+ else {
>+ if (s1) //s2 must have been null
>+ return -1;
>+ if (s2) //s1 must have been null
>+ return 1;
>+ return 0;
>+ }
> }
The coding style says "no else after return", so this should be:
if (s1 && s2 ) {
return !NS_strcmp...
}
if (s1) {
return -1;
}
if (s2) {
return 1;
}
return 0;
And brace all ifs.
>--- a/rdf/base/src/nsRDFService.cpp
>+++ b/rdf/base/src/nsRDFService.cpp
>@@ -168,17 +168,17 @@ struct LiteralHashEntry : public PLDHash
>
> static bool
> MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
> const void *key)
> {
> const LiteralHashEntry *entry =
> static_cast<const LiteralHashEntry *>(hdr);
>
>- return 0 == nsCRT::strcmp(static_cast<const PRUnichar *>(key),
>+ return key && hdr && 0 == NS_strcmp(static_cast<const PRUnichar *>(key),
> entry->mKey);
key can never be null here, so you don't need these nullchecks
>--- a/security/manager/ssl/src/nsCertOverrideService.cpp
>- if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
>+ if (aData && !NS_strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
If you're interested, there's bug X on removing shutdown-cleanse entirely (it's dead code).
r=me with these nits picked. Thanks much!
Attachment #691698 -
Flags: review?(benjamin) → review+
Reporter | ||
Comment 11•12 years ago
|
||
Addresses nits in last comment
Attachment #691698 -
Attachment is obsolete: true
Reporter | ||
Updated•12 years ago
|
Attachment #695166 -
Flags: review+
Attachment #695166 -
Flags: checkin?
Reporter | ||
Comment 12•12 years ago
|
||
Updated to tip
Attachment #695166 -
Attachment is obsolete: true
Attachment #695166 -
Flags: checkin?
Attachment #695403 -
Flags: review+
Attachment #695403 -
Flags: checkin?
Comment 13•12 years ago
|
||
The checkin? patch flag doesn't do much; you really need the checkin-needed keyword.
Keywords: checkin-needed
Updated•12 years ago
|
Assignee: nobody → kshriram18
Comment 14•12 years ago
|
||
Keywords: checkin-needed
Comment 15•12 years ago
|
||
Backed out because it broke the build: https://hg.mozilla.org/integration/mozilla-inbound/rev/652b044f22d6
Comment 16•12 years ago
|
||
(See https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=66a7359f9be2 for build logs.)
Reporter | ||
Comment 17•12 years ago
|
||
(In reply to :Ehsan Akhgari from comment #16)
> (See https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=66a7359f9be2 for
> build logs.)
Taking a look and will send it try to fix this.
Reporter | ||
Updated•12 years ago
|
Status: NEW → ASSIGNED
Updated•12 years ago
|
Attachment #695403 -
Flags: checkin?
Reporter | ||
Updated•10 years ago
|
Assignee: kshriram18 → nobody
Updated•10 years ago
|
Status: ASSIGNED → NEW
Whiteboard: [patchlove]
Updated•10 years ago
|
Updated•2 years ago
|
Severity: minor → S4
You need to log in
before you can comment on or make changes to this bug.
Description
•