Closed Bug 115164 Opened 23 years ago Closed 23 years ago

nsJARURI::FormatSpec does more work than it needs to do

Categories

(Core :: Networking, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla0.9.8

People

(Reporter: darin.moz, Assigned: darin.moz)

References

()

Details

(Keywords: perf)

Attachments

(1 file, 1 obsolete file)

nsJARURI::FormatSpec, which is called by nsJARURI::GetSpec and nsJARURI::Resolve does between 1-2 more strdup's than necessary.
Status: NEW → ASSIGNED
Keywords: perf
Priority: -- → P3
Target Milestone: --- → mozilla0.9.8
Attached patch v1.0 patch (obsolete) — Splinter Review
i haven't measured the performance impact of this patch yet.
dp: can you r= this patch? jag: can you sr= this patch? thx!
Comment on attachment 61669 [details] [diff] [review] v1.0 patch >Index: nsJARURI.cpp >=================================================================== >RCS file: /cvsroot/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp,v >retrieving revision 1.30 >diff -u -r1.30 nsJARURI.cpp >--- nsJARURI.cpp 6 Dec 2001 01:20:33 -0000 1.30 >+++ nsJARURI.cpp 14 Dec 2001 01:39:50 -0000 >@@ -72,24 +72,23 @@ > return NS_OK; > } > >-#define NS_JAR_SCHEME "jar:" >-#define NS_JAR_DELIMITER "!/" >+#define NS_JAR_SCHEME NS_LITERAL_CSTRING("jar:") >+#define NS_JAR_DELIMITER NS_LITERAL_CSTRING("!/") > > nsresult > nsJARURI::FormatSpec(const char* entryPath, char* *result) > { > nsresult rv; >- char* jarFileSpec; >- rv = mJARFile->GetSpec(&jarFileSpec); >+ >+ nsXPIDLCString jarFileSpec; >+ rv = mJARFile->GetSpec(getter_Copies(jarFileSpec)); > if (NS_FAILED(rv)) return rv; > >- nsCAutoString spec(NS_JAR_SCHEME); >- spec += jarFileSpec; >- nsCRT::free(jarFileSpec); >- spec += NS_JAR_DELIMITER; >- spec += entryPath; >- >- *result = ToNewCString(spec); >+ *result = ToNewCString(NS_JAR_SCHEME + >+ jarFileSpec + >+ NS_JAR_DELIMITER + >+ nsDependentCString(entryPath)); >+ > return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; > } > >@@ -140,7 +139,7 @@ > // contained within the bar.jar file. > > nsCAutoString jarPath(aSpec); >- PRInt32 pos = jarPath.RFind(NS_JAR_DELIMITER); >+ PRInt32 pos = jarPath.RFind(NS_JAR_DELIMITER.get()); If you don't want to do this, you can use NS_LITERAL_CSTRING(NS_JAR_SCHEME) above instead of changing the #defines. sr=jag either way.
Attachment #61669 - Flags: superreview+
jag: does the .get() on a literal string result in virtual function calls?
Yes.
Blocks: 7251
Comment on attachment 61669 [details] [diff] [review] v1.0 patch XPIDLCString does a 4 byte alloc. Hence I dont like it. :-( I will leave it to you if you wanna convert back to non-XPIDLCString r=dp
Attachment #61669 - Flags: superreview+ → review+
well... it'd be trivial to rewrite this to just use malloc and memcpy. i think i'll do that instead.
Attached patch v1.1Splinter Review
this patch is better :)
Attachment #61669 - Attachment is obsolete: true
with this patch i noticed a consistent 0.3% startup improvement.
i should have mentioned that my perf measurement was done using an optimized linux build.
Comment on attachment 61780 [details] [diff] [review] v1.1 wow. We could really misuse strings...
Attachment #61780 - Flags: review+
I wish we can do away with the alloc/free for getspec() and have some GetSharedSpec()... sigh!
but doing so would require nsJARURI to also implement GetSharedSpec. doing so means significantly increasing the footprint of a nsJARURI. not sure what's better :(
a good compromise might be a GetSpec(nsAWritableCString &) method. too bad this wouldn't be scriptable :(
jag: can you sr= this latest patch? thx!
Keywords: patch
Comment on attachment 61780 [details] [diff] [review] v1.1 That and you'd have to find a different name since you can't overload methods in idl. Perhaps that const getter is still the best. Or a getter that generates the spec into an existing buffer at the point you hand it. Anyway, sr=jag
Attachment #61780 - Flags: superreview+
fixed-on-trunk
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

Creator:
Created:
Updated:
Size: