Closed Bug 92641 Opened 23 years ago Closed 23 years ago

nsIOService::NewURI strdup's the scheme when it doesn't need to

Categories

(Core :: Networking, defect)

x86
All
defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla0.9.4

People

(Reporter: jesup, Assigned: jesup)

References

Details

(Keywords: perf)

Attachments

(2 files)

nsIOService::NewURI strdup's the scheme when it doesn't need to. I have a patch that avoid's strduping it for URI's with a scheme (I may extend to to some relative URI's as well). This is called circa 1100 times at startup according to Suresh Duddi <dpsuresh@netscape.net>.
Blocks: 67618
Keywords: perf
->dougt, who was looking at string allocations (unless Randell wants to take this)
Assignee: neeti → dougt
I'll take it; I already have a patch coded up (will upload on monday).
Assignee: dougt → rjesup
patch posted; targeting 0.9.4. Anyone who can, r/sr please. According to the posts in .performance, there are at least 1000 uses of this at startup, almost all of which are making an extra allocation of the scheme, so this should save circa 1000 alloc/frees at startup. Future work might be to make the scheme not be allocated in either absolute or relative cases.
Status: NEW → ASSIGNED
Keywords: patch
Target Milestone: --- → mozilla0.9.4
+ if (end != 0 ? !nsCRT::strncasecmp(&scheme[start], gScheme[i], + (end-start)-1) : + !nsCRT::strcasecmp(scheme, gScheme[i])) That was a new construction to me. Took a couple of seconds to figure it out. Why not: PRBool foundScheme; if (end == 0) foundScheme = !nsCRT::strcasecmp(scheme, gScheme[i]) else foundScheme = !nsCRT::strncasecmp(&scheme[start], gScheme[i], (end-start)-1); if (foundScheme) But the idea seems right.
Habit. Totally readable to me to avoid an extra localvar. Any r=/sr=, or if reviewers object, I can recode as Daniel suggests.
Seems like you could use an XPIDLCString for scheme and remove the free call. Other than that, sr=hyatt
what hyatt said. r=dougt
hyatt, dougt: Please either re-review or just tell me to check in. The only change was to use an nsXPIDLCString as suggested. I hadn't before because the original code didn't use one (it did explicit frees). Thanks.
Added waterson; he's my check-in buddy on this. I think we're ready to check in.
Fix checked in
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: