Bug 1451278 - Remove NS_ConstExprIsAscii() functions. r=froydnj draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 05 Apr 2018 11:36:30 +1000
changeset 777583 389c76d78a01ab3bf2957092fe5e6dee5f25964f
parent 777582 5c33f60e0e4c8e38d3f79d1514bbdd6be7c00bcc
push id105253
push usernnethercote@mozilla.com
push dateThu, 05 Apr 2018 01:37:08 +0000
reviewersfroydnj
bugs1451278
milestone61.0a1
Bug 1451278 - Remove NS_ConstExprIsAscii() functions. r=froydnj MozReview-Commit-ID: 9KfPrXPYJaI
xpcom/base/nsCRTGlue.cpp
xpcom/base/nsCRTGlue.h
--- 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_IsAsciiAlpha(char16_t aChar)
 {
   return (aChar >= 'A' && aChar <= 'Z') ||
          (aChar >= 'a' && aChar <= 'z');
 }