Bug 1499212 align Replace/Insert/AppendLiteral parameter restrictions with those of AssignLiteral r=dbaron
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 19 Oct 2018 01:07:41 +0000
changeset 500525 1728cf8a0da4da103076a9e1ce02c9f5b4eb3d85
parent 500524 3f6b347621b3ca43e9c54f36b9721fa4c070eda1
child 500526 18152a7b3fa5e5145b87629c4adf38bfbaf11194
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1499212
milestone64.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 1499212 align Replace/Insert/AppendLiteral parameter restrictions with those of AssignLiteral r=dbaron There is no advantage in making these methods more restrictive on their parameters than AssignLiteral. The current implementation of the AppendLiteral overloads for equivalent char_types is more permissive than AssignLiteral, but comments in the implementation mention the possible optimization used in AssignLiteral and so are assuming a similar constant and static storage duration restriction on its parameter. The optimization may never be implemented, but clients that would benefit from support for non-constant or non-static parameters are also expected to be rare, so there is little value in ruling out the optimization at this stage. ReplaceLiteral currently uses the AssignLiteral optimization. Differential Revision: https://phabricator.services.mozilla.com/D8777
xpcom/string/nsTSubstring.h
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -588,19 +588,21 @@ public:
                                 const char* aData,
                                 size_type aLength = size_type(-1));
 
   MOZ_MUST_USE bool NS_FASTCALL ReplaceASCII(index_type aCutStart, size_type aCutLength,
                                              const char* aData,
                                              size_type aLength,
                                              const fallible_t&);
 
-  // ReplaceLiteral must ONLY be called with an actual literal string.
-  // Do not attempt to use it with a character array variable.
-  // Use Replace or ReplaceASCII for that.
+  // ReplaceLiteral must ONLY be called with an actual literal string, or
+  // a character array *constant* of static storage duration declared
+  // without an explicit size and with an initializer that is a string
+  // literal or is otherwise null-terminated.
+  // Use Replace or ReplaceASCII for other character array variables.
   template<int N>
   void ReplaceLiteral(index_type aCutStart, size_type aCutLength,
                       const char_type (&aStr)[N])
   {
     ReplaceLiteral(aCutStart, aCutLength, aStr, N - 1);
   }
 
   void Append(char_type aChar);
@@ -636,19 +638,21 @@ public:
 
   MOZ_MUST_USE bool AppendASCII(const char* aData,
                                 size_type aLength,
                                 const fallible_t& aFallible);
 
   // Appends a literal string ("" literal in the 8-bit case and u"" literal
   // in the 16-bit case) to the string.
   //
-  // AppendLiteral must ONLY be called with an actual literal string.
-  // Do not attempt to use it with a character array variable.
-  // Use Append or AppendASCII for that.
+  // AppendLiteral must ONLY be called with an actual literal string, or
+  // a character array *constant* of static storage duration declared
+  // without an explicit size and with an initializer that is a string
+  // literal or is otherwise null-terminated.
+  // Use Append or AppendASCII for other character array variables.
   template<int N>
   void AppendLiteral(const char_type (&aStr)[N])
   {
     // The case where base_string_type::mLength is zero is intentionally
     // left unoptimized (could be optimized as call to AssignLiteral),
     // because it's rare/nonexistent. If you add that optimization,
     // please be sure to also check that
     // !(base_string_type::mDataFlags & DataFlags::REFCOUNTED)
@@ -797,19 +801,21 @@ public:
   {
     Replace(aPos, 0, aStr);
   }
   void Insert(const substring_tuple_type& aTuple, index_type aPos)
   {
     Replace(aPos, 0, aTuple);
   }
 
-  // InsertLiteral must ONLY be called with an actual literal string.
-  // Do not attempt to use it with a character array variable.
-  // Use Insert for that.
+  // InsertLiteral must ONLY be called with an actual literal string, or
+  // a character array *constant* of static storage duration declared
+  // without an explicit size and with an initializer that is a string
+  // literal or is otherwise null-terminated.
+  // Use Insert for other character array variables.
   template<int N>
   void InsertLiteral(const char_type (&aStr)[N], index_type aPos)
   {
     ReplaceLiteral(aPos, 0, aStr, N - 1);
   }
 
   void Cut(index_type aCutStart, size_type aCutLength)
   {