Bug 611503 Constructing an nsTDependentString from an nsTAString makes no sense r=dbaron,dwitte
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 14 Sep 2011 20:21:20 +0100
changeset 76957 6f8b4709a5086900076d18eaf5fd343ae08b8135
parent 76956 f483978fe878d5e061b777b59e22a9b48baafa65
child 76958 f2a2adaaacba0f0b1d470430c4fb8f6fb6125fbf
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersdbaron, dwitte
bugs611503
milestone9.0a1
Bug 611503 Constructing an nsTDependentString from an nsTAString makes no sense r=dbaron,dwitte
dom/base/nsDOMClassInfo.cpp
layout/style/nsCSSValue.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
widget/src/xpwidgets/nsXPLookAndFeel.cpp
xpcom/string/public/nsTDependentString.h
xpcom/string/src/nsTDependentString.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -8115,17 +8115,17 @@ nsDOMStringMapSH::Enumerate(nsIXPConnect
   NS_ENSURE_TRUE(dataset, NS_ERROR_UNEXPECTED);
 
   nsDOMStringMap* stringMap = static_cast<nsDOMStringMap*>(dataset.get());
   nsTArray<nsString> properties;
   nsresult rv = stringMap->GetDataPropList(properties);
   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);
     NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
   }
 
   return NS_OK;
 }
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -917,18 +917,17 @@ nsCSSValue::AppendToString(nsCSSProperty
     nsStyleUtil::AppendEscapedCSSString(
       nsDependentString(GetOriginalURLValue()), aResult);
     aResult.Append(NS_LITERAL_STRING(")"));
   }
   else if (eCSSUnit_Element == unit) {
     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) {
     aResult.AppendFloat(GetPercentValue() * 100.0f);
   }
   else if (eCSSUnit_Percent < unit) {  // length unit
     aResult.AppendFloat(GetFloatValue());
   }
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -90,17 +90,18 @@ CookieServiceParent::RecvSetCookieString
     return true;
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI(aHost);
   if (!hostURI)
     return false;
 
+  nsDependentCString cookieString(aCookieString, 0);
   mCookieService->SetCookieStringInternal(hostURI, aIsForeign,
-                                          aCookieString, aServerTime,
+                                          cookieString, aServerTime,
                                           aFromHttp);
   return true;
 }
 
 }
 }
 
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -1488,21 +1488,21 @@ nsCookieService::SetCookieStringCommon(n
   nsDependentCString cookieString(aCookieHeader);
   nsDependentCString serverTime(aServerTime ? aServerTime : "");
   SetCookieStringInternal(aHostURI, isForeign, cookieString,
                           serverTime, aFromHttp);
   return NS_OK;
 }
 
 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!");
 
   if (!mDBState) {
     NS_WARNING("No DBState! Profile already closed?");
     return;
   }
 
@@ -1545,19 +1545,18 @@ nsCookieService::SetCookieStringInternal
                                        &tempServerTime);
   if (result == PR_SUCCESS) {
     serverTime = tempServerTime / PRInt64(PR_USEC_PER_SEC);
   } else {
     serverTime = PR_Now() / PR_USEC_PER_SEC;
   }
 
   // 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;
   }
 }
 
 // notify observers that a cookie was rejected due to the users' prefs.
 void
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -258,17 +258,17 @@ class nsCookieService : public nsICookie
     void                          EnsureReadDomain(const nsCString &aBaseDomain);
     void                          EnsureReadComplete();
     nsresult                      NormalizeHost(nsCString &aHost);
     nsresult                      GetBaseDomain(nsIURI *aHostURI, nsCString &aBaseDomain, PRBool &aRequireHostMatch);
     nsresult                      GetBaseDomainFromHost(const nsACString &aHost, nsCString &aBaseDomain);
     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);
     void                          AddCookieToList(const nsCString& aBaseDomain, nsCookie *aCookie, DBState *aDBState, mozIStorageBindingParamsArray *aParamsArray, PRBool aWriteToDB = PR_TRUE);
     void                          UpdateCookieInList(nsCookie *aCookie, PRInt64 aLastAccessed, mozIStorageBindingParamsArray *aParamsArray);
     static PRBool                 GetTokenValue(nsASingleFragmentCString::const_char_iterator &aIter, nsASingleFragmentCString::const_char_iterator &aEndIter, nsDependentCSubstring &aTokenString, nsDependentCSubstring &aTokenValue, PRBool &aEqualsFound);
     static PRBool                 ParseAttributes(nsDependentCString &aCookieHeader, nsCookieAttributes &aCookie);
     bool                          RequireThirdPartyCheck();
--- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp
+++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp
@@ -325,19 +325,17 @@ nsXPLookAndFeel::ColorPrefChanged (unsig
   nsAutoString colorStr;
   nsresult rv = Preferences::GetString(prefName, &colorStr);
   if (NS_FAILED(rv)) {
     return;
   }
   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);
       }
     } else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
       PRInt32 id = NS_PTR_TO_INT32(index);
       CACHE_COLOR(id, thecolor);
 #ifdef DEBUG_akkana
       printf("====== Changed color pref %s to 0x%lx\n",
--- a/xpcom/string/public/nsTDependentString.h
+++ b/xpcom/string/public/nsTDependentString.h
@@ -86,21 +86,20 @@ class nsTDependentString_CharT : public 
 
       explicit
       nsTDependentString_CharT( const char_type* data )
         : string_type(const_cast<char_type*>(data), PRUint32(char_traits::length(data)), F_TERMINATED)
         {
           AssertValid();
         }
 
-      explicit
-      nsTDependentString_CharT( const substring_type& str )
-        : string_type(const_cast<char_type*>(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
       nsTDependentString_CharT()
         : string_type() {}
 
       // XXX are you sure??
       // auto-generated copy-constructor OK
@@ -119,13 +118,15 @@ class nsTDependentString_CharT : public 
 
       void Rebind( const char_type* data, size_type length );
 
       void Rebind( const char_type* start, const char_type* end )
         {
           Rebind(start, PRUint32(end - start));
         }
 
+      void Rebind( const string_type&, PRUint32 startPos );
+
     private:
       
       // NOT USED
       nsTDependentString_CharT( const substring_tuple_type& );
   };
--- a/xpcom/string/src/nsTDependentString.cpp
+++ b/xpcom/string/src/nsTDependentString.cpp
@@ -43,8 +43,25 @@ nsTDependentString_CharT::Rebind( const 
     // If we currently own a buffer, release it.
     Finalize();
 
     mData = const_cast<char_type*>(data);
     mLength = 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<char_type*>(str.Data()) + startPos;
+    mLength = strLength - startPos;
+
+    SetDataFlags(F_TERMINATED);
+  }