Bug 1386103 (part 2) - Convert nsFixed[C]String uses to nsAuto[C]String. r=erahm.
☠☠ backed out by 81fbe7dc05a6 ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 01 Aug 2017 11:58:56 +1000
changeset 373569 eec506d87d03103778da654b7755b93a8fad7ae9
parent 373568 3f9ec011c9bd5da36b51cb09a81151db70135068
child 373570 81fbe7dc05a694e4e531d163b925e2830dd143d1
push id32304
push usercbook@mozilla.com
push dateWed, 09 Aug 2017 09:37:21 +0000
treeherdermozilla-central@4c5fbf493763 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1386103
milestone57.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 1386103 (part 2) - Convert nsFixed[C]String uses to nsAuto[C]String. r=erahm. In all of these cases the fixed buffer has the same lifetime as the string object, so we can use nsAuto[C]String for simplicity. For the 128-length ones in dom/xul/ I just switched to the default of 64 for simplicity, because the choice of 128 didn't seem that important. (These code paths weren't hit when I started the browser and opened a few sites.) Finally, the patch also changes LoggingIdString to use nsAutoCStringN<NSID_LENGTH>, similar to NullPrincipalURI.
caps/NullPrincipalURI.cpp
caps/NullPrincipalURI.h
dom/indexedDB/ProfilerHelpers.h
dom/ipc/ContentParent.cpp
dom/xul/templates/nsXULContentBuilder.cpp
dom/xul/templates/nsXULContentUtils.cpp
rdf/base/nsRDFContainer.cpp
xpcom/string/nsPrintfCString.h
--- a/caps/NullPrincipalURI.cpp
+++ b/caps/NullPrincipalURI.cpp
@@ -14,40 +14,38 @@
 #include "nsEscape.h"
 #include "nsCRT.h"
 #include "nsIUUIDGenerator.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 //// NullPrincipalURI
 
 NullPrincipalURI::NullPrincipalURI()
-  : mPath(mPathBytes, ArrayLength(mPathBytes), ArrayLength(mPathBytes) - 1)
 {
 }
 
 NullPrincipalURI::NullPrincipalURI(const NullPrincipalURI& aOther)
-  : mPath(mPathBytes, ArrayLength(mPathBytes), ArrayLength(mPathBytes) - 1)
 {
   mPath.Assign(aOther.mPath);
 }
 
 nsresult
 NullPrincipalURI::Init()
 {
   // FIXME: bug 327161 -- make sure the uuid generator is reseeding-resistant.
   nsCOMPtr<nsIUUIDGenerator> uuidgen = services::GetUUIDGenerator();
   NS_ENSURE_TRUE(uuidgen, NS_ERROR_NOT_AVAILABLE);
 
   nsID id;
   nsresult rv = uuidgen->GenerateUUIDInPlace(&id);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  MOZ_ASSERT(mPathBytes == mPath.BeginWriting());
-
-  id.ToProvidedString(mPathBytes);
+  mPath.SetLength(NSID_LENGTH - 1); // -1 because NSID_LENGTH counts the '\0'
+  id.ToProvidedString(
+    *reinterpret_cast<char(*)[NSID_LENGTH]>(mPath.BeginWriting()));
 
   MOZ_ASSERT(mPath.Length() == NSID_LENGTH - 1);
   MOZ_ASSERT(strlen(mPath.get()) == NSID_LENGTH - 1);
 
   return NS_OK;
 }
 
 /* static */
--- a/caps/NullPrincipalURI.h
+++ b/caps/NullPrincipalURI.h
@@ -47,13 +47,12 @@ public:
 
 private:
   NullPrincipalURI(const NullPrincipalURI& aOther);
 
   ~NullPrincipalURI() {}
 
   nsresult Init();
 
-  char mPathBytes[NSID_LENGTH];
-  nsFixedCString mPath;
+  nsAutoCStringN<NSID_LENGTH> mPath;
 };
 
 #endif // __NullPrincipalURI_h__
--- a/dom/indexedDB/ProfilerHelpers.h
+++ b/dom/indexedDB/ProfilerHelpers.h
@@ -32,17 +32,17 @@
 // Include this last to avoid path problems on Windows.
 #include "ActorsChild.h"
 
 namespace mozilla {
 namespace dom {
 namespace indexedDB {
 
 class MOZ_STACK_CLASS LoggingIdString final
-  : public nsAutoCString
+  : public nsAutoCStringN<NSID_LENGTH>
 {
 public:
   LoggingIdString()
   {
     using mozilla::ipc::BackgroundChildImpl;
 
     if (IndexedDatabaseManager::GetLoggingMode() !=
           IndexedDatabaseManager::Logging_Disabled) {
@@ -57,18 +57,19 @@ public:
     }
   }
 
   explicit
   LoggingIdString(const nsID& aID)
   {
     static_assert(NSID_LENGTH > 1, "NSID_LENGTH is set incorrectly!");
     static_assert(NSID_LENGTH <= kStorageSize,
-                  "nID string won't fit in our storage!");
-    MOZ_ASSERT(Capacity() > NSID_LENGTH);
+                  "nsID string won't fit in our storage!");
+    // Capacity() excludes the null terminator; NSID_LENGTH includes it.
+    MOZ_ASSERT(Capacity() + 1 == NSID_LENGTH);
 
     if (IndexedDatabaseManager::GetLoggingMode() !=
           IndexedDatabaseManager::Logging_Disabled) {
       // NSID_LENGTH counts the null terminator, SetLength() does not.
       SetLength(NSID_LENGTH - 1);
 
       aID.ToProvidedString(
         *reinterpret_cast<char(*)[NSID_LENGTH]>(BeginWriting()));
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1973,22 +1973,19 @@ ContentParent::LaunchSubprocess(ProcessP
 
   std::vector<std::string> extraArgs;
   extraArgs.push_back("-childID");
   char idStr[21];
   SprintfLiteral(idStr, "%" PRId64, static_cast<uint64_t>(mChildID));
   extraArgs.push_back(idStr);
   extraArgs.push_back(IsForBrowser() ? "-isForBrowser" : "-notForBrowser");
 
-  char boolBuf[1024];
-  char intBuf[1024];
-  char strBuf[1024];
-  nsFixedCString boolPrefs(boolBuf, 1024, 0);
-  nsFixedCString intPrefs(intBuf, 1024, 0);
-  nsFixedCString stringPrefs(strBuf, 1024, 0);
+  nsAutoCStringN<1024> boolPrefs;
+  nsAutoCStringN<1024> intPrefs;
+  nsAutoCStringN<1024> stringPrefs;
 
   size_t prefsLen;
   ContentPrefs::GetContentPrefs(&prefsLen);
 
   for (unsigned int i = 0; i < prefsLen; i++) {
     MOZ_ASSERT(i == 0 || strcmp(ContentPrefs::GetContentPref(i), ContentPrefs::GetContentPref(i - 1)) > 0);
     switch (Preferences::GetType(ContentPrefs::GetContentPref(i))) {
     case nsIPrefBranch::PREF_INT:
--- a/dom/xul/templates/nsXULContentBuilder.cpp
+++ b/dom/xul/templates/nsXULContentBuilder.cpp
@@ -595,18 +595,17 @@ nsXULContentBuilder::BuildContentFromTem
         }
         else if (tag == nsGkAtoms::textnode &&
                  nameSpaceID == kNameSpaceID_XUL) {
             // <xul:text value="..."> is replaced by text of the
             // actual value of the 'rdf:resource' attribute for the
             // given node.
             // SynchronizeUsingTemplate contains code used to update textnodes,
             // so make sure to modify both when changing this
-            char16_t attrbuf[128];
-            nsFixedString attrValue(attrbuf, ArrayLength(attrbuf), 0);
+            nsAutoString attrValue;
             tmplKid->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
             if (!attrValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aChild, attrValue, value);
                 if (NS_FAILED(rv)) return rv;
 
                 RefPtr<nsTextNode> content =
                   new nsTextNode(mRoot->NodeInfo()->NodeInfoManager());
@@ -732,21 +731,17 @@ nsXULContentBuilder::CopyAttributesToEle
         const nsAttrName* name = aTemplateNode->GetAttrNameAt(attr);
         int32_t attribNameSpaceID = name->NamespaceID();
         // Hold a strong reference here so that the atom doesn't go away
         // during UnsetAttr.
         nsCOMPtr<nsIAtom> attribName = name->LocalName();
 
         // XXXndeakin ignore namespaces until bug 321182 is fixed
         if (attribName != nsGkAtoms::id && attribName != nsGkAtoms::uri) {
-            // Create a buffer here, because there's a chance that an
-            // attribute in the template is going to be an RDF URI, which is
-            // usually longish.
-            char16_t attrbuf[128];
-            nsFixedString attribValue(attrbuf, ArrayLength(attrbuf), 0);
+            nsAutoString attribValue;
             aTemplateNode->GetAttr(attribNameSpaceID, attribName, attribValue);
             if (!attribValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aResult, attribValue, value);
                 if (NS_FAILED(rv))
                     return rv;
 
                 // if the string is empty after substitutions, remove the
@@ -873,18 +868,17 @@ nsXULContentBuilder::SynchronizeUsingTem
         nsIContent *realKid = aRealElement->GetChildAt(loop);
         if (! realKid)
             break;
 
         // check for text nodes and update them accordingly.
         // This code is similar to that in BuildContentFromTemplate
         if (tmplKid->NodeInfo()->Equals(nsGkAtoms::textnode,
                                         kNameSpaceID_XUL)) {
-            char16_t attrbuf[128];
-            nsFixedString attrValue(attrbuf, ArrayLength(attrbuf), 0);
+            nsAutoString attrValue;
             tmplKid->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
             if (!attrValue.IsEmpty()) {
                 nsAutoString value;
                 rv = SubstituteText(aResult, attrValue, value);
                 if (NS_FAILED(rv)) return rv;
                 realKid->SetText(value, true);
             }
         }
--- a/dom/xul/templates/nsXULContentUtils.cpp
+++ b/dom/xul/templates/nsXULContentUtils.cpp
@@ -250,18 +250,17 @@ nsXULContentUtils::GetResource(int32_t a
 
     // XXX should we allow nodes with no namespace???
     //NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "no namespace");
     //if (aNameSpaceID == kNameSpaceID_Unknown)
     //    return NS_ERROR_UNEXPECTED;
 
     nsresult rv;
 
-    char16_t buf[256];
-    nsFixedString uri(buf, ArrayLength(buf), 0);
+    nsAutoStringN<256> uri;
     if (aNameSpaceID != kNameSpaceID_Unknown && aNameSpaceID != kNameSpaceID_None) {
         rv = nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, uri);
         // XXX ignore failure; treat as "no namespace"
     }
 
     // XXX check to see if we need to insert a '/' or a '#'. Oy.
     if (!uri.IsEmpty()  && uri.Last() != '#' && uri.Last() != '/' && aAttribute.First() != '#')
         uri.Append(char16_t('#'));
--- a/rdf/base/nsRDFContainer.cpp
+++ b/rdf/base/nsRDFContainer.cpp
@@ -682,18 +682,17 @@ RDFContainerImpl::GetNextValue(nsIRDFRes
                 break;
 
             nextVal *= 10;
             nextVal += *p - '0';
         }
     }
 
     static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
-    char buf[sizeof(kRDFNameSpaceURI) + 16];
-    nsFixedCString nextValStr(buf, sizeof(buf), 0);
+    nsAutoCStringN<sizeof(kRDFNameSpaceURI) + 16> nextValStr;
     nextValStr = kRDFNameSpaceURI;
     nextValStr.Append('_');
     nextValStr.AppendInt(nextVal, 10);
 
     rv = gRDFService->GetResource(nextValStr, aResult);
     if (NS_FAILED(rv)) return rv;
 
     // Now increment the RDF:nextVal property.
--- a/xpcom/string/nsPrintfCString.h
+++ b/xpcom/string/nsPrintfCString.h
@@ -15,28 +15,23 @@
  *
  *   NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get());
  *
  * nsPrintfCString has a small built-in auto-buffer.  For larger strings, it
  * will allocate on the heap.
  *
  * See also nsCString::AppendPrintf().
  */
-class nsPrintfCString : public nsFixedCString
+class nsPrintfCString : public nsAutoCStringN<16>
 {
   typedef nsCString string_type;
 
 public:
   explicit nsPrintfCString(const char_type* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3)
-    : nsFixedCString(mLocalBuffer, kLocalBufferSize, 0)
   {
     va_list ap;
     va_start(ap, aFormat);
     AppendPrintf(aFormat, ap);
     va_end(ap);
   }
-
-private:
-  static const uint32_t kLocalBufferSize = 16;
-  char_type mLocalBuffer[kLocalBufferSize];
 };
 
 #endif // !defined(nsPrintfCString_h___)