Closed Bug 81762 Opened 24 years ago Closed 24 years ago

Excessive use of strlen

Categories

(SeaMonkey :: UI Design, defect, P3)

defect

Tracking

(Not tracked)

VERIFIED FIXED
mozilla0.9.6

People

(Reporter: drepper, Assigned: paulkchen)

References

Details

(Keywords: perf)

Attachments

(2 files, 3 obsolete files)

The files appshell/src/nsCommandLineService.cpp appshell/src/nsCommandLineServiceMac.cpp appshell/src/nsFileLocations.cpp appshell/src/nsUserInfoUnix.cpp contain unnecessary uses of the function nsCRT::strlen which cannot be optimized out by the compiler since it doesn't know the function is the same as strlen. The patch mostly replaces expressions like strlen(foo) > 0 with foo[0] != '\0' or something similar. Only in the file appshell/src/nsCommandLineServiceMac.cpp there is another optimization. The handling of the kCommandLinePrefix and kEnvVarLinePrefix were less than optimal. The changes remove two function calls and two extra variables (the pointers, simply define two arrays). The patch is tested except for the Macintosh portion.
Attached patch strlen optimizations (obsolete) — Splinter Review
Keywords: patch, perf
nav triage team: Not a beta stopper, marking nsbeta1- and marking future
Keywords: nsbeta1-
Target Milestone: --- → Future
Blocks: 71874
No longer blocks: 71874
Blocks: 71874
For whatever it's worth, the patch looks just fine to me (r=rjesup@wgate.com, not that I'm an approved reviewer). Severity -> minor Nominating for 1.0; it's a trivial & safe patch if it hasn't bit-rotted too badly. Probably should remove nsbeta1- I advise dropping Milestone: future.
Keywords: qawantedmozilla1.0
removing nsbeta1-, marking p3 and mozilla0.9.6
Status: NEW → ASSIGNED
Keywords: nsbeta1-
Priority: -- → P3
Target Milestone: Future → mozilla0.9.6
cc-ing Simon to look over the patch and give an sr= if it meets with his approval
One difference between PR_strlen and strlen is that the former deals gracefully with null strings. That patch should be reviewed with that in mind. rs=sfraser
Attached patch updated patch (obsolete) — Splinter Review
Attachment #35276 - Attachment is obsolete: true
Just posted a new patch, main difference is that I don't change from PL_strlen if we don't first check for null.
The new patch isn't correct. Take this: - (void)AddToCommandLine(chars + PL_strlen(kCommandLinePrefix)); + (void)AddToCommandLine(chars + sizeof(kCommandLinePrefix)); This patch changes the behavior since sizeof() counts the terminating \0 byte in while strlen of course doesn't. If you look at my patch you'll see that I added -1 to compensate for that.
Attachment #55754 - Attachment is obsolete: true
Attached patch ooops, forgot the -1 (obsolete) — Splinter Review
yet another patch, thanks for catching that one
Attachment #55778 - Attachment is obsolete: true
Ok, new patch. This one is the same as the first patch submitted by Ulrich, the difference is that I add checks for null pointer where needed.
Attachment #55942 - Flags: review+
Comment on attachment 55942 [details] [diff] [review] hopefully last patch @@ -168,7 +168,7 @@ rv = GetDomain(getter_Copies(domain)); if (NS_FAILED(rv)) return rv; - if ((const char *)username && (const char*)domain && nsCRT::strlen((const char *)username) && nsCRT::strlen((const char *)domain)) { + if ((const char *)username && (const char*)domain && ((const char *)username)[0] && ((const char *)domain)[0]) { emailAddress = (const char *)username; emailAddress += "@"; emailAddress += (const char *)domain; |domain| and |username| are |nsXPIDLCString|s, so you can just check |IsEmpty()|. Fix that and r=jag.
Comment on attachment 56014 [details] [diff] [review] updated nsUserInfoUnix.cpp patch with jag's suggestion jag said r= if I updated this part
Attachment #56014 - Flags: review+
sr=sfraser
checked into trunk and I fixed the blah.IsEmpty() to !blah.IsEmpty() error in my last patch
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
QA Contact: sairuh → jrgm
vrfy (checked in).
Status: RESOLVED → VERIFIED
Product: Core → Mozilla Application Suite
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: