Bug 611503 Constructing an nsTDependentString from an nsTAString makes no sense r=dbaron,dwitte
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 15 Sep 2011 08:40:17 +0100
changeset 78270 f1eef5e80caf7271ef046bc0081da3c9088d1b0d
parent 78269 f2a2adaaacba0f0b1d470430c4fb8f6fb6125fbf
child 78271 5faaa652594fd7c8fc9db1fdf84f5dcf930f3ea2
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron, dwitte
bugs611503
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 611503 Constructing an nsTDependentString from an nsTAString makes no sense r=dbaron,dwitte
dom/base/nsDOMClassInfo.cpp
gfx/thebes/gfxFT2FontList.cpp
layout/style/nsCSSValue.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
widget/src/android/AndroidBridge.cpp
widget/src/android/AndroidBridge.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/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -307,18 +307,17 @@ gfxFT2FontList::GetDefaultFont(const gfx
     if (hGDI && ::GetObjectW(hGDI, sizeof(logFont), &logFont)) {
         nsAutoString resolvedName;
         if (ResolveFontName(nsDependentString(logFont.lfFaceName), resolvedName)) {
             return FindFontForFamily(resolvedName, aStyle, aNeedsBold);
         }
     }
 #elif defined(ANDROID)
     nsAutoString resolvedName;
-    if (ResolveFontName(nsDependentString(NS_LITERAL_STRING("Droid Sans")), 
-                        resolvedName))
+    if (ResolveFontName(NS_LITERAL_STRING("Droid Sans"), resolvedName))
         return FindFontForFamily(resolvedName, aStyle, aNeedsBold);
 #endif
     /* TODO: what about Qt or other platforms that may use this? */
     return nsnull;
 }
 
 gfxFontEntry*
 gfxFT2FontList::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
--- 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/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
+++ b/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
@@ -84,17 +84,17 @@ nsMIMEInfoAndroid::GetMimeInfoForMimeTyp
   nsIHandlerApp* systemDefault = nsnull;
   bridge->GetHandlersForMimeType(nsCAutoString(aMimeType).get(), 
                                  info->mHandlerApps, &systemDefault);
   
   if (systemDefault)
     info->mPrefApp = systemDefault;
 
   nsCAutoString fileExt;
-  bridge->GetExtensionFromMimeType(nsDependentCString(aMimeType), fileExt);
+  bridge->GetExtensionFromMimeType(aMimeType, fileExt);
   info->SetPrimaryExtension(fileExt);
   
   PRUint32 len;
   info->mHandlerApps->GetLength(&len);
   if (len == 1) {
     info.forget(aMimeInfo);
     return PR_FALSE;
   }
--- a/widget/src/android/AndroidBridge.cpp
+++ b/widget/src/android/AndroidBridge.cpp
@@ -489,17 +489,17 @@ AndroidBridge::GetMimeTypeFromExtensions
         mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
                                         jGetMimeTypeFromExtensions,
                                         jstrExt));
     nsJNIString jniStr(jstrType);
     aMimeType.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
 }
 
 void
-AndroidBridge::GetExtensionFromMimeType(const nsCString& aMimeType, nsACString& aFileExt)
+AndroidBridge::GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt)
 {
     ALOG_BRIDGE("AndroidBridge::GetExtensionFromMimeType");
 
     AutoLocalJNIFrame jniFrame;
     NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
     jstring jstrType = mJNIEnv->NewString(wMimeType.get(), wMimeType.Length());
     jstring jstrExt = static_cast<jstring>(
         mJNIEnv->CallStaticObjectMethod(mGeckoAppShellClass,
--- a/widget/src/android/AndroidBridge.h
+++ b/widget/src/android/AndroidBridge.h
@@ -157,17 +157,17 @@ public:
 
     PRBool OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
                            const nsAString& aPackageName = EmptyString(),
                            const nsAString& aClassName = EmptyString(),
                            const nsAString& aAction = EmptyString(),
                            const nsAString& aTitle = EmptyString());
 
     void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
-    void GetExtensionFromMimeType(const nsCString& aMimeType, nsACString& aFileExt);
+    void GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt);
 
     void MoveTaskToBack();
 
     bool GetClipboardText(nsAString& aText);
 
     void SetClipboardText(const nsAString& aText);
     
     void EmptyClipboard();
--- 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);
+  }