+2015-11-01 Darin Adler <darin@apple.com>
+
+ ASCIICType refinements
+ https://bugs.webkit.org/show_bug.cgi?id=150787
+
+ Reviewed by Geoffrey Garen.
+
+ Refined ASCIICType.h by using narrower types. The most valuable part of this
+ is the part where the result of toASCIIHexValue is uint8_t instead of int;
+ that's slightly better for RGB values that the compiler needs to know fit
+ into a byte (coming in some Color work I plan to do soon).
+
+ * wtf/ASCIICType.h: Used CharacterType instead of CharType throughout, and
+ also sorted the using declarations at the bottom of the header.
+ (WTF::isASCII): Use the name "character" instead of "c".
+ (WTF::isASCIIAlpha): Ditto. Also use isASCIILower and toASCIILowerUnchecked
+ instead of writing it out.
+ (WTF::isASCIIDigit): Ditto.
+ (WTF::isASCIIAlphanumeric): Ditto.
+ (WTF::isASCIIHexDigit): Ditto. Also use toASCIILowerUnchecked instead of
+ writing it out.
+ (WTF::isASCIILower): Ditto.
+ (WTF::isASCIIBinaryDigit): Ditto. Also removed unneeded parentheses to match
+ the style of the rest of the file.
+ (WTF::isASCIIOctalDigit): Ditto.
+ (WTF::isASCIIPrintable): Ditto.
+ (WTF::isASCIISpace): Ditto.
+ (WTF::isASCIIUpper): Ditto.
+ (WTF::toASCIILower): Ditto. Also use isASCIIUpper instead of writing it out.
+ (WTF::toASCIILowerUnchecked): Tweaked comment.
+ (WTF::toASCIIUpper): Ditto. Also use isASCIILower instead of writing it out.
+ (WTF::toASCIIHexValue): Ditto. Also change return type from int to uint8_t.
+ Also broke a single assertion with && into two separate assertions and got
+ rid of unnnecessary masking with 0xF0 after shifting left. Also renamed
+ arguments for the two argument value so they are more sensible.
+ (WTF::lowerNibbleToASCIIHexDigit): Changed argument type to uint8_t, since
+ this function does not take a character. Also called it "value" instead of "c".
+ Also slightly tweaked how the expression is written.
+ (WTF::upperNibbleToASCIIHexDigit): Ditto. Using the more specific type also
+ got rid of the need to explicitly mask in this function.
+ (WTF::isASCIIAlphaCaselessEqual): Renamed the arguments for greater clarity.
+ With the new clearer argument names, the comment was superfluous.
+
2015-11-01 Filip Pizlo <fpizlo@apple.com>
Dominators should be factored out of the DFG
/*
- * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2009, 2011, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
-template<typename CharType> inline bool isASCII(CharType c)
+template<typename CharacterType> inline bool isASCII(CharacterType character)
{
- return !(c & ~0x7F);
+ return !(character & ~0x7F);
}
-template<typename CharType> inline bool isASCIIAlpha(CharType c)
+template<typename CharacterType> inline bool isASCIILower(CharacterType character)
{
- return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
+ return character >= 'a' && character <= 'z';
}
-template<typename CharType> inline bool isASCIIDigit(CharType c)
+template<typename CharacterType> inline CharacterType toASCIILowerUnchecked(CharacterType character)
{
- return c >= '0' && c <= '9';
+ // This function can be used for comparing any input character
+ // to a lowercase English character. The isASCIIAlphaCaselessEqual
+ // below should be used for regular comparison of ASCII alpha
+ // characters, but switch statements in CSS tokenizer instead make
+ // direct use of this function.
+ return character | 0x20;
}
-template<typename CharType> inline bool isASCIIAlphanumeric(CharType c)
+template<typename CharacterType> inline bool isASCIIAlpha(CharacterType character)
{
- return isASCIIDigit(c) || isASCIIAlpha(c);
+ return isASCIILower(toASCIILowerUnchecked(character));
}
-template<typename CharType> inline bool isASCIIHexDigit(CharType c)
+template<typename CharacterType> inline bool isASCIIDigit(CharacterType character)
{
- return isASCIIDigit(c) || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
+ return character >= '0' && character <= '9';
}
-template<typename CharType> inline bool isASCIILower(CharType c)
+template<typename CharacterType> inline bool isASCIIAlphanumeric(CharacterType character)
{
- return c >= 'a' && c <= 'z';
+ return isASCIIDigit(character) || isASCIIAlpha(character);
}
-template<typename CharType> inline bool isASCIIBinaryDigit(CharType c)
+template<typename CharacterType> inline bool isASCIIHexDigit(CharacterType character)
{
- return (c == '0') || (c == '1');
+ return isASCIIDigit(character) || (toASCIILowerUnchecked(character) >= 'a' && toASCIILowerUnchecked(character) <= 'f');
}
-template<typename CharType> inline bool isASCIIOctalDigit(CharType c)
+template<typename CharacterType> inline bool isASCIIBinaryDigit(CharacterType character)
{
- return (c >= '0') && (c <= '7');
+ return character == '0' || character == '1';
}
-template<typename CharType> inline bool isASCIIPrintable(CharType c)
+template<typename CharacterType> inline bool isASCIIOctalDigit(CharacterType character)
{
- return c >= ' ' && c <= '~';
+ return character >= '0' && character <= '7';
}
-/*
- Statistics from a run of Apple's page load test for callers of isASCIISpace:
-
- character count
- --------- -----
- non-spaces 689383
- 20 space 294720
- 0A \n 89059
- 09 \t 28320
- 0D \r 0
- 0C \f 0
- 0B \v 0
- */
-template<typename CharType> inline bool isASCIISpace(CharType c)
+template<typename CharacterType> inline bool isASCIIPrintable(CharacterType character)
{
- return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
+ return character >= ' ' && character <= '~';
}
-template<typename CharType> inline bool isASCIIUpper(CharType c)
+/*
+ Statistics from a run of Apple's page load test for callers of isASCIISpace:
+
+ character count
+ --------- -----
+ non-spaces 689383
+ 20 space 294720
+ 0A \n 89059
+ 09 \t 28320
+ 0D \r 0
+ 0C \f 0
+ 0B \v 0
+
+ Because of those, we first check to quickly return false for non-control characters,
+ then check for space itself to quickly return true for that case, then do the rest.
+*/
+template<typename CharacterType> inline bool isASCIISpace(CharacterType character)
{
- return c >= 'A' && c <= 'Z';
+ return character <= ' ' && (character == ' ' || (character <= 0xD && character >= 0x9));
}
-template<typename CharType> inline CharType toASCIILower(CharType c)
+template<typename CharacterType> inline bool isASCIIUpper(CharacterType character)
{
- return c | ((c >= 'A' && c <= 'Z') << 5);
+ return character >= 'A' && character <= 'Z';
}
-template<>
-inline char toASCIILower(char c)
+template<typename CharacterType> inline CharacterType toASCIILower(CharacterType character)
{
- return static_cast<char>(asciiCaseFoldTable[static_cast<unsigned char>(c)]);
+ return character | (isASCIIUpper(character) << 5);
}
-template<>
-inline LChar toASCIILower(LChar c)
+template<> inline char toASCIILower(char character)
{
- return asciiCaseFoldTable[c];
+ return static_cast<char>(asciiCaseFoldTable[static_cast<uint8_t>(character)]);
}
-template<typename CharType> inline CharType toASCIILowerUnchecked(CharType character)
+template<> inline LChar toASCIILower(LChar character)
{
- // This function can be used for comparing any input character
- // to a lowercase English character. The isASCIIAlphaCaselessEqual
- // below should be used for regular comparison of ASCII alpha
- // characters, but switch statements in CSS tokenizer require
- // direct use of this function.
- return character | 0x20;
+ return asciiCaseFoldTable[character];
}
-template<typename CharType> inline CharType toASCIIUpper(CharType c)
+template<typename CharacterType> inline CharacterType toASCIIUpper(CharacterType character)
{
- return c & ~((c >= 'a' && c <= 'z') << 5);
+ return character & ~(isASCIILower(character) << 5);
}
-template<typename CharType> inline int toASCIIHexValue(CharType c)
+template<typename CharacterType> inline uint8_t toASCIIHexValue(CharacterType character)
{
- ASSERT(isASCIIHexDigit(c));
- return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
+ ASSERT(isASCIIHexDigit(character));
+ return character < 'A' ? character - '0' : (character - 'A' + 10) & 0xF;
}
-template<typename CharType> inline int toASCIIHexValue(CharType upperValue, CharType lowerValue)
+template<typename CharacterType> inline uint8_t toASCIIHexValue(CharacterType firstCharacter, CharacterType secondCharacter)
{
- ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue));
- return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue);
+ return toASCIIHexValue(firstCharacter) << 4 | toASCIIHexValue(secondCharacter);
}
-inline char lowerNibbleToASCIIHexDigit(char c)
+inline char lowerNibbleToASCIIHexDigit(uint8_t value)
{
- char nibble = c & 0xF;
- return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
+ uint8_t nibble = value & 0xF;
+ return nibble + (nibble < 10 ? '0' : 'A' - 10);
}
-inline char upperNibbleToASCIIHexDigit(char c)
+inline char upperNibbleToASCIIHexDigit(uint8_t value)
{
- char nibble = (c >> 4) & 0xF;
- return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
+ uint8_t nibble = value >> 4;
+ return nibble + (nibble < 10 ? '0' : 'A' - 10);
}
-template<typename CharType> inline bool isASCIIAlphaCaselessEqual(CharType cssCharacter, char character)
+template<typename CharacterType> inline bool isASCIIAlphaCaselessEqual(CharacterType inputCharacter, char expectedASCIILowercaseLetter)
{
- // This function compares a (preferrably) constant ASCII
- // lowercase letter to any input character.
- ASSERT(character >= 'a' && character <= 'z');
- return LIKELY(toASCIILowerUnchecked(cssCharacter) == character);
+ ASSERT(isASCIILower(expectedASCIILowercaseLetter));
+ return LIKELY(toASCIILowerUnchecked(inputCharacter) == expectedASCIILowercaseLetter);
}
}
using WTF::isASCII;
using WTF::isASCIIAlpha;
+using WTF::isASCIIAlphaCaselessEqual;
using WTF::isASCIIAlphanumeric;
+using WTF::isASCIIBinaryDigit;
using WTF::isASCIIDigit;
using WTF::isASCIIHexDigit;
using WTF::isASCIILower;
-using WTF::isASCIIBinaryDigit;
using WTF::isASCIIOctalDigit;
using WTF::isASCIIPrintable;
using WTF::isASCIISpace;
using WTF::isASCIIUpper;
+using WTF::lowerNibbleToASCIIHexDigit;
using WTF::toASCIIHexValue;
using WTF::toASCIILower;
using WTF::toASCIILowerUnchecked;
using WTF::toASCIIUpper;
-using WTF::lowerNibbleToASCIIHexDigit;
using WTF::upperNibbleToASCIIHexDigit;
-using WTF::isASCIIAlphaCaselessEqual;
#endif