Bug 1451535 - Remove NS_ConstExprIsAscii() functions. r=froydnj
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 17 Apr 2018 20:03:52 +0900
changeset 467637 d9eb07a242d4570d97d79f18db8ed79703cfb22b
parent 467636 a31b222963a1c8ef3b2d5006ed52e26d71e62473
child 467638 079bd3d58e34e91d002f906748be9f62f0aec318
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1451535
milestone61.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 1451535 - Remove NS_ConstExprIsAscii() functions. r=froydnj
dom/media/gmp/GMPChild.cpp
xpcom/base/nsCRTGlue.cpp
xpcom/base/nsCRTGlue.h
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -284,17 +284,17 @@ GMPChild::RecvPreloadLibs(const nsCStrin
   // Items in this must be lowercase!
   constexpr static const char16_t* whitelist[] = {
     u"dxva2.dll", // Get monitor information
     u"evr.dll", // MFGetStrideForBitmapInfoHeader
     u"mfplat.dll", // MFCreateSample, MFCreateAlignedMemoryBuffer, MFCreateMediaType
     u"msmpeg2vdec.dll", // H.264 decoder
     u"psapi.dll", // For GetMappedFileNameW, see bug 1383611
   };
-  constexpr static bool (*IsASCII)(const char16_t*) = NS_ConstExprIsAscii;
+  constexpr static bool (*IsASCII)(const char16_t*) = NS_IsAscii;
   static_assert(AllOf(std::begin(whitelist), std::end(whitelist), IsASCII),
                 "Items in the whitelist must not contain non-ASCII "
                 "characters!");
 
   nsTArray<nsCString> libs;
   SplitAt(", ", aLibs, libs);
   for (nsCString lib : libs) {
     ToLowerCase(lib);
--- a/xpcom/base/nsCRTGlue.cpp
+++ b/xpcom/base/nsCRTGlue.cpp
@@ -211,53 +211,16 @@ NS_IsUpper(char aChar)
 }
 
 bool
 NS_IsLower(char aChar)
 {
   return aChar != (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar];
 }
 
-bool
-NS_IsAscii(const char16_t* aString)
-{
-  while (*aString) {
-    if (0x0080 <= *aString) {
-      return false;
-    }
-    aString++;
-  }
-  return true;
-}
-
-bool
-NS_IsAscii(const char* aString)
-{
-  while (*aString) {
-    if (0x80 & *aString) {
-      return false;
-    }
-    aString++;
-  }
-  return true;
-}
-
-bool
-NS_IsAscii(const char* aString, uint32_t aLength)
-{
-  const char* end = aString + aLength;
-  while (aString < end) {
-    if (0x80 & *aString) {
-      return false;
-    }
-    ++aString;
-  }
-  return true;
-}
-
 #ifndef XPCOM_GLUE_AVOID_NSPR
 
 void
 NS_MakeRandomString(char* aBuf, int32_t aBufLen)
 {
 #define TABLE_SIZE 36
   static const char table[] = {
     'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
--- a/xpcom/base/nsCRTGlue.h
+++ b/xpcom/base/nsCRTGlue.h
@@ -99,44 +99,51 @@ bool NS_IsUpper(char aChar);
 bool NS_IsLower(char aChar);
 
 constexpr bool
 NS_IsAscii(char16_t aChar)
 {
   return (0x0080 > aChar);
 }
 
-bool NS_IsAscii(const char16_t* aString);
-bool NS_IsAscii(const char* aString);
-bool NS_IsAscii(const char* aString, uint32_t aLength);
-
-// These three functions are `constexpr` alternatives to NS_IsAscii. It should
-// only be used for compile-time computation because it uses recursion.
-// XXX: once support for GCC 4.9 is dropped, this function should be removed
-// and NS_IsAscii should be made `constexpr`.
 constexpr bool
-NS_ConstExprIsAscii(const char16_t* aString)
+NS_IsAscii(const char16_t* aString)
 {
-  return !*aString ? true :
-    !NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
+  while (*aString) {
+    if (0x0080 <= *aString) {
+      return false;
+    }
+    aString++;
+  }
+  return true;
 }
 
 constexpr bool
-NS_ConstExprIsAscii(const char* aString)
+NS_IsAscii(const char* aString)
 {
-  return !*aString ? true :
-    !NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
+  while (*aString) {
+    if (0x80 & *aString) {
+      return false;
+    }
+    aString++;
+  }
+  return true;
 }
 
 constexpr bool
-NS_ConstExprIsAscii(const char* aString, uint32_t aLength)
+NS_IsAscii(const char* aString, uint32_t aLength)
 {
-  return aLength == 0 ? true :
-    !NS_IsAscii(*aString) ? false :
-    NS_ConstExprIsAscii(aString + 1, aLength - 1);
+  const char* end = aString + aLength;
+  while (aString < end) {
+    if (0x80 & *aString) {
+      return false;
+    }
+    aString++;
+  }
+  return true;
 }
 
 constexpr bool
 NS_IsAsciiWhitespace(char16_t aChar)
 {
   return aChar == ' ' ||
          aChar == '\r' ||
          aChar == '\n' ||