Bug 1499212 - document reasons for restrictions on EqualsLiteral parameter r=dbaron
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 19 Oct 2018 00:57:49 +0000
changeset 500522 19e29511c546e968d4d0ef6469a114267f1fa415
parent 500521 9469c37cc124badf9e8cfd29be4469f50a9c2c47
child 500523 9cc9c8d06722b89670910b8d61ee41f884c43e48
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 - document reasons for restrictions on EqualsLiteral parameter r=dbaron "Bound" is the term used in the C++ standard to describe the number of elements in an array. EqualsLiteral has no opportunity to optimize for constant and static storage duration parameters. Depends on D8773 Differential Revision: https://phabricator.services.mozilla.com/D8774
xpcom/string/nsTStringRepr.h
--- a/xpcom/string/nsTStringRepr.h
+++ b/xpcom/string/nsTStringRepr.h
@@ -256,17 +256,20 @@ public:
   // for wide strings. Call this version when 'data' is
   // null-terminated.
   bool NS_FASTCALL EqualsASCII(const char* aData) const;
 
   // EqualsLiteral must ONLY be applied to an actual literal string, or
   // a char array *constant* declared without an explicit size.
   // Do not attempt to use it with a non-constant char array variable.
   // Use EqualsASCII for that.
-  // The template trick to acquire the array length at compile time without
+  // (Although this method may happen to produce expected results for other
+  // char arrays that have bound one greater than the sequence of interest,
+  // such use is discouraged for reasons of readability and maintainability.)
+  // The template trick to acquire the array bound at compile time without
   // using a macro is due to Corey Kosak, with much thanks.
   template<int N>
   inline bool EqualsLiteral(const char (&aStr)[N]) const
   {
     return EqualsASCII(aStr, N - 1);
   }
 
   // The LowerCaseEquals methods compare the ASCII-lowercase version of
@@ -278,16 +281,19 @@ public:
   bool NS_FASTCALL LowerCaseEqualsASCII(const char* aData,
                                         size_type aLen) const;
   bool NS_FASTCALL LowerCaseEqualsASCII(const char* aData) const;
 
   // LowerCaseEqualsLiteral must ONLY be applied to an actual
   // literal string, or a char array *constant* declared without an
   // explicit size.  Do not attempt to use it with a non-constant char array
   // variable. Use LowerCaseEqualsASCII for that.
+  // (Although this method may happen to produce expected results for other
+  // char arrays that have bound one greater than the sequence of interest,
+  // such use is discouraged for reasons of readability and maintainability.)
   template<int N>
   bool LowerCaseEqualsLiteral(const char (&aStr)[N]) const
   {
     return LowerCaseEqualsASCII(aStr, N - 1);
   }
 
   // Returns true if this string overlaps with the given string fragment.
   bool IsDependentOn(const char_type* aStart, const char_type* aEnd) const