From b6778f6858484f5f751068a44b71a9f051e2e539 Mon Sep 17 00:00:00 2001 From: "dwitte%stanford.edu" Date: Sat, 19 Jul 2003 14:58:33 +0000 Subject: [PATCH] make nsStandardURL::GetFile cache its result and use nsIFile::Clone when handing it out. we unfortunately need to clone until consumers of this method are fixed to not modify the returned file (see bug 212724). this should reduce Ts some... b=122892, r=andreas.otte, sr=darin, with many thanks to biesi & mkaply for testing on other plats. git-svn-id: svn://10.0.0.236/trunk@144972 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/netwerk/base/src/nsStandardURL.cpp | 51 ++++++++++------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/mozilla/netwerk/base/src/nsStandardURL.cpp b/mozilla/netwerk/base/src/nsStandardURL.cpp index 1cbc21d5bcc..61fe44fb036 100644 --- a/mozilla/netwerk/base/src/nsStandardURL.cpp +++ b/mozilla/netwerk/base/src/nsStandardURL.cpp @@ -2185,43 +2185,38 @@ nsStandardURL::SetFileExtension(const nsACString &input) NS_IMETHODIMP nsStandardURL::GetFile(nsIFile **result) { - // use cached result if present - if (mFile) { - NS_ADDREF(*result = mFile); - return NS_OK; + // reparse the spec if we don't have a cached result + if (!mFile) { + if (mSpec.IsEmpty()) { + NS_ERROR("url not initialized"); + return NS_ERROR_NOT_INITIALIZED; + } + + if (!SegmentIs(mScheme, "file")) { + NS_ERROR("not a file URL"); + return NS_ERROR_FAILURE; + } + + nsresult rv = net_GetFileFromURLSpec(mSpec, getter_AddRefs(mFile)); + if (NS_FAILED(rv)) return rv; } - if (mSpec.IsEmpty()) { - NS_ERROR("url not initialized"); - return NS_ERROR_NOT_INITIALIZED; - } - - if (!SegmentIs(mScheme, "file")) { - NS_ERROR("not a file URL"); - return NS_ERROR_FAILURE; - } - - nsresult rv = net_GetFileFromURLSpec(mSpec, result); - - // XXX ultimately, we should probably cache this result to speed - // up subsequent calls, but past attempts to do so have been - // met with nasty smoketest blockers (e.g., see bug 161921). - // it seems that some folks like to modify the returned nsIFile, - // so we'd have to clone the result before handing it out. - // unfortunately, there are bugs in the implementation(s) of - // nsIFile::clone that prevent us from using this as a solution - // right now (see bug 122892). - #if defined(PR_LOGGING) - if (NS_SUCCEEDED(rv) && LOG_ENABLED()) { + if (LOG_ENABLED()) { nsCAutoString path; - (*result)->GetNativePath(path); + mFile->GetNativePath(path); LOG(("nsStandardURL::GetFile [this=%p spec=%s resulting_path=%s]\n", this, mSpec.get(), path.get())); } #endif - return rv; + // clone the file, so the caller can modify it. + // XXX nsIFileURL.idl specifies that the consumer must _not_ modify the + // nsIFile returned from this method; but it seems that some folks do + // (see bug 161921). until we can be sure that all the consumers are + // behaving themselves, we'll stay on the safe side and clone the file. + // see bug 212724 about fixing the consumers. + return mFile->Clone(result); } NS_IMETHODIMP