From a7c255d1c9db86f4892ac6d7fdbb76eaf95558e5 Mon Sep 17 00:00:00 2001 From: Neil Rashbrook Date: Wed, 14 Sep 2011 20:21:20 +0100 Subject: [PATCH] Bug 611503 Constructing an nsTDependentString from an nsTAString makes no sense r=dbaron,dwitte --- dom/base/nsDOMClassInfo.cpp | 2 +- layout/style/nsCSSValue.cpp | 3 +-- netwerk/cookie/CookieServiceParent.cpp | 3 ++- netwerk/cookie/nsCookieService.cpp | 15 +++++++-------- netwerk/cookie/nsCookieService.h | 2 +- widget/src/xpwidgets/nsXPLookAndFeel.cpp | 4 +--- xpcom/string/public/nsTDependentString.h | 9 +++++---- xpcom/string/src/nsTDependentString.cpp | 17 +++++++++++++++++ 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 8f25dfa3c6f..43c80b78a21 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -8120,7 +8120,7 @@ nsDOMStringMapSH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, NS_ENSURE_SUCCESS(rv, rv); for (PRUint32 i = 0; i < properties.Length(); ++i) { - nsDependentString prop(properties[i]); + nsString& prop(properties[i]); *_retval = JS_DefineUCProperty(cx, obj, prop.get(), prop.Length(), JSVAL_VOID, nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_SHARED); diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 6fd4e0c2993..a303eff1336 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -922,8 +922,7 @@ nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const aResult.Append(NS_LITERAL_STRING("-moz-element(#")); nsAutoString tmpStr; GetStringValue(tmpStr); - nsStyleUtil::AppendEscapedCSSIdent( - nsDependentString(tmpStr), aResult); + nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult); aResult.Append(NS_LITERAL_STRING(")")); } else if (eCSSUnit_Percent == unit) { diff --git a/netwerk/cookie/CookieServiceParent.cpp b/netwerk/cookie/CookieServiceParent.cpp index 47e72da16f1..c2d3185c4a7 100644 --- a/netwerk/cookie/CookieServiceParent.cpp +++ b/netwerk/cookie/CookieServiceParent.cpp @@ -95,8 +95,9 @@ CookieServiceParent::RecvSetCookieString(const IPC::URI& aHost, if (!hostURI) return false; + nsDependentCString cookieString(aCookieString, 0); mCookieService->SetCookieStringInternal(hostURI, aIsForeign, - aCookieString, aServerTime, + cookieString, aServerTime, aFromHttp); return true; } diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 5893a06551d..93d4da4348e 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -1493,11 +1493,11 @@ nsCookieService::SetCookieStringCommon(nsIURI *aHostURI, } void -nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, - bool aIsForeign, - const nsCString &aCookieHeader, - const nsCString &aServerTime, - PRBool aFromHttp) +nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, + bool aIsForeign, + nsDependentCString &aCookieHeader, + const nsCString &aServerTime, + PRBool aFromHttp) { NS_ASSERTION(aHostURI, "null host!"); @@ -1550,9 +1550,8 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, } // process each cookie in the header - nsDependentCString cookieHeader(aCookieHeader); - while (SetCookieInternal(aHostURI, baseDomain, requireHostMatch, - cookieStatus, cookieHeader, serverTime, aFromHttp)) { + while (SetCookieInternal(aHostURI, baseDomain, requireHostMatch, cookieStatus, + aCookieHeader, serverTime, aFromHttp)) { // document.cookie can only set one cookie at a time if (!aFromHttp) break; diff --git a/netwerk/cookie/nsCookieService.h b/netwerk/cookie/nsCookieService.h index 6fced2621b0..267ce7bc61e 100644 --- a/netwerk/cookie/nsCookieService.h +++ b/netwerk/cookie/nsCookieService.h @@ -263,7 +263,7 @@ class nsCookieService : public nsICookieService nsresult GetCookieStringCommon(nsIURI *aHostURI, nsIChannel *aChannel, bool aHttpBound, char** aCookie); void GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, PRBool aHttpBound, nsCString &aCookie); nsresult SetCookieStringCommon(nsIURI *aHostURI, const char *aCookieHeader, const char *aServerTime, nsIChannel *aChannel, bool aFromHttp); - void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, const nsCString &aCookieHeader, const nsCString &aServerTime, PRBool aFromHttp); + void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, nsDependentCString &aCookieHeader, const nsCString &aServerTime, PRBool aFromHttp); PRBool SetCookieInternal(nsIURI *aHostURI, const nsCString& aBaseDomain, PRBool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, PRInt64 aServerTime, PRBool aFromHttp); void AddInternal(const nsCString& aBaseDomain, nsCookie *aCookie, PRInt64 aCurrentTimeInUsec, nsIURI *aHostURI, const char *aCookieHeader, PRBool aFromHttp); void RemoveCookieFromList(const nsListIter &aIter, mozIStorageBindingParamsArray *aParamsArray = NULL); diff --git a/widget/src/xpwidgets/nsXPLookAndFeel.cpp b/widget/src/xpwidgets/nsXPLookAndFeel.cpp index e698a1c4e77..d106e73bde4 100644 --- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp +++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp @@ -330,9 +330,7 @@ nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName) if (!colorStr.IsEmpty()) { nscolor thecolor; if (colorStr[0] == PRUnichar('#')) { - if (NS_HexToRGB(nsDependentString( - Substring(colorStr, 1, colorStr.Length() - 1)), - &thecolor)) { + if (NS_HexToRGB(nsDependentString(colorStr, 1), &thecolor)) { PRInt32 id = NS_PTR_TO_INT32(index); CACHE_COLOR(id, thecolor); } diff --git a/xpcom/string/public/nsTDependentString.h b/xpcom/string/public/nsTDependentString.h index a9192e02a4c..818f7200d03 100644 --- a/xpcom/string/public/nsTDependentString.h +++ b/xpcom/string/public/nsTDependentString.h @@ -91,11 +91,10 @@ class nsTDependentString_CharT : public nsTString_CharT AssertValid(); } - explicit - nsTDependentString_CharT( const substring_type& str ) - : string_type(const_cast(str.Data()), str.Length(), F_TERMINATED) + nsTDependentString_CharT( const string_type& str, PRUint32 startPos ) + : string_type() { - AssertValid(); + Rebind(str, startPos); } // Create a nsTDependentSubstring to be bound later @@ -124,6 +123,8 @@ class nsTDependentString_CharT : public nsTString_CharT Rebind(start, PRUint32(end - start)); } + void Rebind( const string_type&, PRUint32 startPos ); + private: // NOT USED diff --git a/xpcom/string/src/nsTDependentString.cpp b/xpcom/string/src/nsTDependentString.cpp index f1dd21cc926..88a41f448fd 100644 --- a/xpcom/string/src/nsTDependentString.cpp +++ b/xpcom/string/src/nsTDependentString.cpp @@ -48,3 +48,20 @@ nsTDependentString_CharT::Rebind( const char_type* data, size_type length ) SetDataFlags(F_TERMINATED); AssertValid(); } + +void +nsTDependentString_CharT::Rebind( const string_type& str, PRUint32 startPos ) + { + // If we currently own a buffer, release it. + Finalize(); + + size_type strLength = str.Length(); + + if (startPos > strLength) + startPos = strLength; + + mData = const_cast(str.Data()) + startPos; + mLength = strLength - startPos; + + SetDataFlags(F_TERMINATED); + }