зеркало из https://github.com/mozilla/gecko-dev.git
Merge mozilla-central to inbound. a=merge CLOSED TREE
This commit is contained in:
Коммит
12088e3639
|
@ -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_IsAscii;
|
||||
constexpr static bool (*IsASCII)(const char16_t*) = NS_ConstExprIsAscii;
|
||||
static_assert(AllOf(std::begin(whitelist), std::end(whitelist), IsASCII),
|
||||
"Items in the whitelist must not contain non-ASCII "
|
||||
"characters!");
|
||||
|
|
|
@ -210,16 +210,29 @@ HashGeneric(Args... aArgs)
|
|||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
constexpr uint32_t
|
||||
uint32_t
|
||||
HashUntilZero(const T* aStr)
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
for (; T c = *aStr; aStr++) {
|
||||
for (T c; (c = *aStr); aStr++) {
|
||||
hash = AddToHash(hash, c);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
// This is a `constexpr` alternative to HashUntilZero(const T*). 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 HashUntilZero(const T*) should be made `constexpr`.
|
||||
template<typename T>
|
||||
constexpr uint32_t
|
||||
ConstExprHashUntilZero(const T* aStr, uint32_t aHash)
|
||||
{
|
||||
return !*aStr
|
||||
? aHash
|
||||
: ConstExprHashUntilZero(aStr + 1, AddToHash(aHash, *aStr));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
uint32_t
|
||||
HashKnownLength(const T* aStr, size_t aLength)
|
||||
|
@ -258,15 +271,27 @@ HashString(const unsigned char* aStr, size_t aLength)
|
|||
return detail::HashKnownLength(aStr, aLength);
|
||||
}
|
||||
|
||||
// You may need to use the
|
||||
// MOZ_{PUSH,POP}_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING macros if you use
|
||||
// this function. See the comment on those macros' definitions for more detail.
|
||||
MOZ_MUST_USE constexpr uint32_t
|
||||
MOZ_MUST_USE inline uint32_t
|
||||
HashString(const char16_t* aStr)
|
||||
{
|
||||
return detail::HashUntilZero(aStr);
|
||||
}
|
||||
|
||||
// This is a `constexpr` alternative to HashString(const char16_t*). It should
|
||||
// only be used for compile-time computation because it uses recursion.
|
||||
//
|
||||
// You may need to use the
|
||||
// MOZ_{PUSH,POP}_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING macros if you use
|
||||
// this function. See the comment on those macros' definitions for more detail.
|
||||
//
|
||||
// XXX: once support for GCC 4.9 is dropped, this function should be removed
|
||||
// and HashString(const char16_t*) should be made `constexpr`.
|
||||
MOZ_MUST_USE constexpr uint32_t
|
||||
ConstExprHashString(const char16_t* aStr)
|
||||
{
|
||||
return detail::ConstExprHashUntilZero(aStr, 0);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE inline uint32_t
|
||||
HashString(const char16_t* aStr, size_t aLength)
|
||||
{
|
||||
|
|
|
@ -216,6 +216,43 @@ 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
|
||||
|
|
|
@ -104,41 +104,34 @@ 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_IsAscii(const char16_t* aString)
|
||||
NS_ConstExprIsAscii(const char16_t* aString)
|
||||
{
|
||||
while (*aString) {
|
||||
if (0x0080 <= *aString) {
|
||||
return false;
|
||||
}
|
||||
aString++;
|
||||
}
|
||||
return true;
|
||||
return !*aString ? true :
|
||||
!NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
NS_IsAscii(const char* aString)
|
||||
NS_ConstExprIsAscii(const char* aString)
|
||||
{
|
||||
while (*aString) {
|
||||
if (0x80 & *aString) {
|
||||
return false;
|
||||
}
|
||||
aString++;
|
||||
}
|
||||
return true;
|
||||
return !*aString ? true :
|
||||
!NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
NS_IsAscii(const char* aString, uint32_t aLength)
|
||||
NS_ConstExprIsAscii(const char* aString, uint32_t aLength)
|
||||
{
|
||||
const char* end = aString + aLength;
|
||||
while (aString < end) {
|
||||
if (0x80 & *aString) {
|
||||
return false;
|
||||
}
|
||||
aString++;
|
||||
}
|
||||
return true;
|
||||
return aLength == 0 ? true :
|
||||
!NS_IsAscii(*aString) ? false :
|
||||
NS_ConstExprIsAscii(aString + 1, aLength - 1);
|
||||
}
|
||||
|
||||
constexpr bool
|
||||
|
|
|
@ -107,7 +107,7 @@ protected:
|
|||
constexpr nsAtom(const char16_t* aStr, uint32_t aLength)
|
||||
: mLength(aLength)
|
||||
, mKind(static_cast<uint32_t>(nsAtom::AtomKind::Static))
|
||||
, mHash(mozilla::HashString(aStr))
|
||||
, mHash(mozilla::ConstExprHashString(aStr))
|
||||
{}
|
||||
|
||||
// Used by nsDynamicAtom.
|
||||
|
|
Загрузка…
Ссылка в новой задаче