Skip to content

Commit

Permalink
Bug 1451278 - Remove NS_ConstExprIsAscii() functions. r=froydnj
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: DG2HUOa7x6y
  • Loading branch information
nnethercote committed Apr 15, 2018
1 parent 6028aa9 commit 1875e26
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dom/media/gmp/GMPChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ GMPChild::RecvPreloadLibs(const nsCString& aLibs)
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!");
Expand Down
37 changes: 0 additions & 37 deletions xpcom/base/nsCRTGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,43 +216,6 @@ 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
Expand Down
43 changes: 25 additions & 18 deletions xpcom/base/nsCRTGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,41 @@ 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
Expand Down

0 comments on commit 1875e26

Please sign in to comment.