зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1542736
- Part 2: Replace JS7_ISHEX with mozilla::IsAsciiHexDigit. r=jwalden
Clang and GCC generate slightly better assembly when IsAsciiHexDigit is called, because the `cmp` instruction for the `< 127` check in JS7_ISHEX is no longer emitted. Differential Revision: https://phabricator.services.mozilla.com/D26505 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
429f41348e
Коммит
4a0bd67ecd
|
@ -69,6 +69,7 @@ using JS::SymbolCode;
|
|||
|
||||
using mozilla::AsciiAlphanumericToNumber;
|
||||
using mozilla::CheckedInt;
|
||||
using mozilla::IsAsciiHexDigit;
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::IsSame;
|
||||
using mozilla::PodCopy;
|
||||
|
@ -230,7 +231,8 @@ static inline bool Unhex4(const RangedPtr<const CharT> chars,
|
|||
char16_t* result) {
|
||||
CharT a = chars[0], b = chars[1], c = chars[2], d = chars[3];
|
||||
|
||||
if (!(JS7_ISHEX(a) && JS7_ISHEX(b) && JS7_ISHEX(c) && JS7_ISHEX(d))) {
|
||||
if (!(IsAsciiHexDigit(a) && IsAsciiHexDigit(b) && IsAsciiHexDigit(c) &&
|
||||
IsAsciiHexDigit(d))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,7 @@ static inline bool Unhex2(const RangedPtr<const CharT> chars,
|
|||
char16_t* result) {
|
||||
CharT a = chars[0], b = chars[1];
|
||||
|
||||
if (!(JS7_ISHEX(a) && JS7_ISHEX(b))) {
|
||||
if (!(IsAsciiHexDigit(a) && IsAsciiHexDigit(b))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3980,7 +3982,7 @@ static DecodeResult Decode(StringBuffer& sb, const CharT* chars, size_t length,
|
|||
return Decode_BadUri;
|
||||
}
|
||||
|
||||
if (!JS7_ISHEX(chars[k + 1]) || !JS7_ISHEX(chars[k + 2])) {
|
||||
if (!IsAsciiHexDigit(chars[k + 1]) || !IsAsciiHexDigit(chars[k + 2])) {
|
||||
return Decode_BadUri;
|
||||
}
|
||||
|
||||
|
@ -4021,7 +4023,8 @@ static DecodeResult Decode(StringBuffer& sb, const CharT* chars, size_t length,
|
|||
return Decode_BadUri;
|
||||
}
|
||||
|
||||
if (!JS7_ISHEX(chars[k + 1]) || !JS7_ISHEX(chars[k + 2])) {
|
||||
if (!IsAsciiHexDigit(chars[k + 1]) ||
|
||||
!IsAsciiHexDigit(chars[k + 2])) {
|
||||
return Decode_BadUri;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ using mozilla::DecodeOneUtf8CodePoint;
|
|||
using mozilla::IsAscii;
|
||||
using mozilla::IsAsciiAlpha;
|
||||
using mozilla::IsAsciiDigit;
|
||||
using mozilla::IsAsciiHexDigit;
|
||||
using mozilla::IsTrailingUnit;
|
||||
using mozilla::MakeScopeExit;
|
||||
using mozilla::MakeSpan;
|
||||
|
@ -1550,7 +1551,7 @@ uint32_t GeneralTokenStreamChars<Unit, AnyCharsAccess>::matchUnicodeEscape(
|
|||
|
||||
char16_t v;
|
||||
unit = getCodeUnit();
|
||||
if (JS7_ISHEX(unit) && this->sourceUnits.matchHexDigits(3, &v)) {
|
||||
if (IsAsciiHexDigit(unit) && this->sourceUnits.matchHexDigits(3, &v)) {
|
||||
*codePoint = (AsciiAlphanumericToNumber(unit) << 12) | v;
|
||||
return 5;
|
||||
}
|
||||
|
@ -1583,7 +1584,7 @@ GeneralTokenStreamChars<Unit, AnyCharsAccess>::matchExtendedUnicodeEscape(
|
|||
|
||||
size_t i = 0;
|
||||
uint32_t code = 0;
|
||||
while (JS7_ISHEX(unit) && i < 6) {
|
||||
while (IsAsciiHexDigit(unit) && i < 6) {
|
||||
code = (code << 4) | AsciiAlphanumericToNumber(unit);
|
||||
unit = getCodeUnit();
|
||||
i++;
|
||||
|
@ -2591,7 +2592,7 @@ MOZ_MUST_USE bool TokenStreamSpecific<Unit, AnyCharsAccess>::getTokenInternal(
|
|||
if (unit == 'x' || unit == 'X') {
|
||||
radix = 16;
|
||||
unit = getCodeUnit();
|
||||
if (!JS7_ISHEX(unit)) {
|
||||
if (!IsAsciiHexDigit(unit)) {
|
||||
// NOTE: |unit| may be EOF here.
|
||||
ungetCodeUnit(unit);
|
||||
error(JSMSG_MISSING_HEXDIGITS);
|
||||
|
@ -2601,7 +2602,7 @@ MOZ_MUST_USE bool TokenStreamSpecific<Unit, AnyCharsAccess>::getTokenInternal(
|
|||
// one past the '0x'
|
||||
numStart = this->sourceUnits.addressOfNextCodeUnit() - 1;
|
||||
|
||||
while (JS7_ISHEX(unit)) {
|
||||
while (IsAsciiHexDigit(unit)) {
|
||||
unit = getCodeUnit();
|
||||
}
|
||||
} else if (unit == 'b' || unit == 'B') {
|
||||
|
@ -3173,7 +3174,7 @@ bool TokenStreamSpecific<Unit, AnyCharsAccess>::getStringOrTemplateToken(
|
|||
|
||||
// Beware: |u3| may be a non-ASCII code point here; if
|
||||
// so it'll pass into this |if|-block.
|
||||
if (!JS7_ISHEX(u3)) {
|
||||
if (!IsAsciiHexDigit(u3)) {
|
||||
if (parsingTemplate) {
|
||||
// We put the code unit back so that we read it
|
||||
// on the next pass, which matters if it was
|
||||
|
@ -3224,7 +3225,7 @@ bool TokenStreamSpecific<Unit, AnyCharsAccess>::getStringOrTemplateToken(
|
|||
// template literal, we must defer error reporting because
|
||||
// malformed escapes are okay in *tagged* template literals.
|
||||
char16_t v;
|
||||
if (JS7_ISHEX(c2) && this->sourceUnits.matchHexDigits(3, &v)) {
|
||||
if (IsAsciiHexDigit(c2) && this->sourceUnits.matchHexDigits(3, &v)) {
|
||||
unit = (AsciiAlphanumericToNumber(c2) << 12) | v;
|
||||
} else {
|
||||
// Beware: |c2| may not be an ASCII code point here!
|
||||
|
|
|
@ -1220,7 +1220,7 @@ class SourceUnits {
|
|||
char16_t v = 0;
|
||||
for (uint8_t i = 0; i < n; i++) {
|
||||
auto unit = CodeUnitValue(ptr[i]);
|
||||
if (!JS7_ISHEX(unit)) {
|
||||
if (!mozilla::IsAsciiHexDigit(unit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,9 @@ class JSLinearString;
|
|||
* Manually inline isdigit and isxdigit for performance; MSVC doesn't do this
|
||||
* for us.
|
||||
*/
|
||||
#define JS7_ISA2F(c) \
|
||||
((((((unsigned)(c)) - 'a') <= 5) || (((unsigned)(c)) - 'A') <= 5))
|
||||
#define JS7_UNDEC(c) ((c) - '0')
|
||||
#define JS7_ISOCT(c) ((((unsigned)(c)) - '0') <= 7)
|
||||
#define JS7_UNOCT(c) (JS7_UNDEC(c))
|
||||
#define JS7_ISHEX(c) ((c) < 128 && (mozilla::IsAsciiDigit(c) || JS7_ISA2F(c)))
|
||||
|
||||
static MOZ_ALWAYS_INLINE size_t js_strlen(const char16_t* s) {
|
||||
return std::char_traits<char16_t>::length(s);
|
||||
|
|
|
@ -25,6 +25,7 @@ using namespace js;
|
|||
|
||||
using mozilla::AsciiAlphanumericToNumber;
|
||||
using mozilla::IsAsciiDigit;
|
||||
using mozilla::IsAsciiHexDigit;
|
||||
using mozilla::RangedPtr;
|
||||
|
||||
JSONParserBase::~JSONParserBase() {
|
||||
|
@ -204,17 +205,17 @@ JSONParserBase::Token JSONParser<CharT>::readString() {
|
|||
|
||||
case 'u':
|
||||
if (end - current < 4 ||
|
||||
!(JS7_ISHEX(current[0]) && JS7_ISHEX(current[1]) &&
|
||||
JS7_ISHEX(current[2]) && JS7_ISHEX(current[3]))) {
|
||||
!(IsAsciiHexDigit(current[0]) && IsAsciiHexDigit(current[1]) &&
|
||||
IsAsciiHexDigit(current[2]) && IsAsciiHexDigit(current[3]))) {
|
||||
// Point to the first non-hexadecimal character (which may be
|
||||
// missing).
|
||||
if (current == end || !JS7_ISHEX(current[0])) {
|
||||
if (current == end || !IsAsciiHexDigit(current[0])) {
|
||||
; // already at correct location
|
||||
} else if (current + 1 == end || !JS7_ISHEX(current[1])) {
|
||||
} else if (current + 1 == end || !IsAsciiHexDigit(current[1])) {
|
||||
current += 1;
|
||||
} else if (current + 2 == end || !JS7_ISHEX(current[2])) {
|
||||
} else if (current + 2 == end || !IsAsciiHexDigit(current[2])) {
|
||||
current += 2;
|
||||
} else if (current + 3 == end || !JS7_ISHEX(current[3])) {
|
||||
} else if (current + 3 == end || !IsAsciiHexDigit(current[3])) {
|
||||
current += 3;
|
||||
} else {
|
||||
MOZ_CRASH("logic error determining first erroneous character");
|
||||
|
|
Загрузка…
Ссылка в новой задаче