From 0f2c763c77b964899295abdeffa3de9d814130fd Mon Sep 17 00:00:00 2001 From: "dp%netscape.com" Date: Tue, 21 Aug 2001 20:09:20 +0000 Subject: [PATCH] Bug 94366 Reducing url object creations by not converting urls schemes that done need conversion to absolute. r,sr=waterson --- rdf/base/src/rdfutil.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/rdf/base/src/rdfutil.cpp b/rdf/base/src/rdfutil.cpp index 7911ebbcbee..d7421548a6a 100644 --- a/rdf/base/src/rdfutil.cpp +++ b/rdf/base/src/rdfutil.cpp @@ -87,18 +87,33 @@ rdf_MakeRelativeName(const nsString& aBaseURI, nsString& aURI) } +static PRBool +rdf_RequiresAbsoluteURI(const nsString& uri) +{ + // cheap shot at figuring out if this requires an absolute url translation + if (Substring(uri, 0, 4).Equals(NS_LITERAL_STRING("urn:")) || + Substring(uri, 0, 9).Equals(NS_LITERAL_STRING("chrome:")) || + !Compare(Substring(uri, 0, 3), NS_LITERAL_STRING("nc:"), + nsCaseInsensitiveStringComparator())) { + return PR_FALSE; + } + return PR_TRUE; +} + nsresult rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI) { nsresult rv; nsAutoString result; + if (!rdf_RequiresAbsoluteURI(aURI)) + return NS_OK; + nsCOMPtr base; rv = NS_NewURI(getter_AddRefs(base), aBaseURI); if (NS_FAILED(rv)) return rv; rv = NS_MakeAbsoluteURI(result, aURI, base); - if (NS_FAILED(rv)) return rv; if (NS_SUCCEEDED(rv)) { aURI = result; @@ -114,12 +129,16 @@ rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI) nsresult -rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI) +rdf_MakeAbsoluteURI(nsIURI* aBase, nsString& aURI) { nsresult rv; + + if (!rdf_RequiresAbsoluteURI(aURI)) + return NS_OK; + nsAutoString result; - rv = NS_MakeAbsoluteURI(result, aURI, aURL); + rv = NS_MakeAbsoluteURI(result, aURI, aBase); if (NS_SUCCEEDED(rv)) { aURI = result; @@ -134,12 +153,12 @@ rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI) } nsresult -rdf_MakeAbsoluteURI(nsIURI* aURL, nsCString& aURI) +rdf_MakeAbsoluteURI(nsIURI* aBase, nsCString& aURI) { nsresult rv; nsXPIDLCString result; - rv = NS_MakeAbsoluteURI(getter_Copies(result), aURI.get(), aURL); + rv = NS_MakeAbsoluteURI(getter_Copies(result), aURI.get(), aBase); if (NS_SUCCEEDED(rv)) { aURI.Assign(result);