Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp |
| diff --git a/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp b/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp |
| index 888ca97a67c350195d18c12fb2b5fbb94bf19434..d7ca2b8201c6efe8c28b5ad41e599f9e4a43c943 100644 |
| --- a/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp |
| +++ b/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp |
| @@ -86,6 +86,125 @@ StringToUnitTable& unitTable() |
| return unitTable; |
| } |
| +template<typename CharacterType> |
| +CSSPrimitiveValue::UnitType toUnitType(CharacterType* chars, unsigned length) |
|
esprehn
2016/04/22 23:30:57
This was a very big improvement, it skips malloc o
|
| +{ |
| + switch (length) { |
| + case 0: |
| + return CSSPrimitiveValue::UnitType::UserUnits; |
| + case 1: |
| + if (toASCIILower(chars[0]) == 's') |
|
Timothy Loh
2016/04/27 06:52:05
toASCIILowerUnchecked or isASCIIAlphaCaselessEqual
|
| + return CSSPrimitiveValue::UnitType::Seconds; |
| + break; |
| + case 2: |
| + switch (toASCIILower(chars[0])) { |
| + case 'c': |
| + switch (toASCIILower(chars[1])) { |
| + case 'h': |
| + return CSSPrimitiveValue::UnitType::Chs; |
| + case 'm': |
| + return CSSPrimitiveValue::UnitType::Centimeters; |
| + } |
| + break; |
| + case 'e': |
| + switch (toASCIILower(chars[1])) { |
| + case 'm': |
| + return CSSPrimitiveValue::UnitType::Ems; |
| + case 'x': |
| + return CSSPrimitiveValue::UnitType::Exs; |
| + } |
| + break; |
| + case 'f': |
| + if (toASCIILower(chars[0]) == 'r') |
| + return CSSPrimitiveValue::UnitType::Fraction; |
| + break; |
| + case 'h': |
| + if (toASCIILower(chars[0]) == 'z') |
| + return CSSPrimitiveValue::UnitType::Hertz; |
| + break; |
| + case 'i': |
| + if (toASCIILower(chars[0]) == 'n') |
| + return CSSPrimitiveValue::UnitType::Inches; |
| + break; |
| + case 'm': |
| + switch (toASCIILower(chars[1])) { |
| + case 'm': |
| + return CSSPrimitiveValue::UnitType::Millimeters; |
| + case 's': |
| + return CSSPrimitiveValue::UnitType::Milliseconds; |
| + } |
| + break; |
| + case 'p': |
| + switch (toASCIILower(chars[1])) { |
| + case 'c': |
| + return CSSPrimitiveValue::UnitType::Picas; |
| + case 't': |
| + return CSSPrimitiveValue::UnitType::Points; |
| + case 'x': |
| + return CSSPrimitiveValue::UnitType::Pixels; |
| + } |
| + break; |
| + case 'v': |
| + switch (toASCIILower(chars[1])) { |
| + case 'h': |
| + return CSSPrimitiveValue::UnitType::ViewportHeight; |
| + case 'w': |
| + return CSSPrimitiveValue::UnitType::ViewportWidth; |
| + } |
| + break; |
| + } |
| + break; |
| + case 3: |
| + switch (toASCIILower(chars[0])) { |
| + case 'd': |
| + switch (toASCIILower(chars[1])) { |
| + case 'e': |
| + if (toASCIILower(chars[2]) == 'g') |
| + return CSSPrimitiveValue::UnitType::Degrees; |
| + break; |
| + case 'p': |
| + if (toASCIILower(chars[2]) == 'i') |
| + return CSSPrimitiveValue::UnitType::DotsPerInch; |
| + break; |
| + } |
| + break; |
| + case 'k': |
| + if (toASCIILower(chars[1]) == 'h' && toASCIILower(chars[2]) == 'z') |
| + return CSSPrimitiveValue::UnitType::Kilohertz; |
| + break; |
| + case 'r': |
| + switch (toASCIILower(chars[1])) { |
| + case 'a': |
| + if (toASCIILower(chars[2]) == 'd') |
| + return CSSPrimitiveValue::UnitType::Radians; |
| + break; |
| + case 'e': |
| + if (toASCIILower(chars[2]) == 'm') |
| + return CSSPrimitiveValue::UnitType::Rems; |
| + break; |
| + } |
| + break; |
| + } |
| + break; |
| + case 4: |
| + // "grad" |
| + // "dpcm" |
| + // "dppx" |
| + // "vmin" |
| + // "vmax" |
| + // "turns" |
| + // TODO(esprehn): Use the trie here too. |
| + return unitTable().get(String(chars, length).lower()); |
| + break; |
| + case 5: |
| + // "__qem" |
|
Timothy Loh
2016/04/27 06:52:05
this isn't exposed, if it helps we can rename it t
|
| + // TODO(esprehn): Use the trie here too. |
| + return unitTable().get(String(chars, length).lower()); |
| + break; |
| + } |
| + return CSSPrimitiveValue::UnitType::Unknown; |
| +} |
| + |
| } // namespace |
| float CSSPrimitiveValue::clampToCSSLengthRange(double value) |
| @@ -102,7 +221,19 @@ void CSSPrimitiveValue::initUnitTable() |
| CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit) |
| { |
| - return unitTable().get(unit.lower()); |
| + if (unit.is8Bit()) |
| + return toUnitType(unit.characters8(), unit.length()); |
| + return toUnitType(unit.characters16(), unit.length()); |
| +} |
| + |
| +CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const LChar* characters8, unsigned length) |
| +{ |
| + return toUnitType(characters8, length); |
| +} |
| + |
| +CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const UChar* characters16, unsigned length) |
| +{ |
| + return toUnitType(characters16, length); |
| } |
| CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitTypeToUnitCategory(UnitType type) |