Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp

Issue 1920583002: NOT FOR LANDING: Hack up CSSParser for speed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing consts. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 table.set(String("__qem"), CSSPrimitiveValue::UnitType::QuirkyEms); 79 table.set(String("__qem"), CSSPrimitiveValue::UnitType::QuirkyEms);
80 return table; 80 return table;
81 } 81 }
82 82
83 StringToUnitTable& unitTable() 83 StringToUnitTable& unitTable()
84 { 84 {
85 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() )); 85 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() ));
86 return unitTable; 86 return unitTable;
87 } 87 }
88 88
89 template<typename CharacterType>
90 CSSPrimitiveValue::UnitType toUnitType(CharacterType* chars, unsigned length)
esprehn 2016/04/22 23:30:57 This was a very big improvement, it skips malloc o
91 {
92 switch (length) {
93 case 0:
94 return CSSPrimitiveValue::UnitType::UserUnits;
95 case 1:
96 if (toASCIILower(chars[0]) == 's')
Timothy Loh 2016/04/27 06:52:05 toASCIILowerUnchecked or isASCIIAlphaCaselessEqual
97 return CSSPrimitiveValue::UnitType::Seconds;
98 break;
99 case 2:
100 switch (toASCIILower(chars[0])) {
101 case 'c':
102 switch (toASCIILower(chars[1])) {
103 case 'h':
104 return CSSPrimitiveValue::UnitType::Chs;
105 case 'm':
106 return CSSPrimitiveValue::UnitType::Centimeters;
107 }
108 break;
109 case 'e':
110 switch (toASCIILower(chars[1])) {
111 case 'm':
112 return CSSPrimitiveValue::UnitType::Ems;
113 case 'x':
114 return CSSPrimitiveValue::UnitType::Exs;
115 }
116 break;
117 case 'f':
118 if (toASCIILower(chars[0]) == 'r')
119 return CSSPrimitiveValue::UnitType::Fraction;
120 break;
121 case 'h':
122 if (toASCIILower(chars[0]) == 'z')
123 return CSSPrimitiveValue::UnitType::Hertz;
124 break;
125 case 'i':
126 if (toASCIILower(chars[0]) == 'n')
127 return CSSPrimitiveValue::UnitType::Inches;
128 break;
129 case 'm':
130 switch (toASCIILower(chars[1])) {
131 case 'm':
132 return CSSPrimitiveValue::UnitType::Millimeters;
133 case 's':
134 return CSSPrimitiveValue::UnitType::Milliseconds;
135 }
136 break;
137 case 'p':
138 switch (toASCIILower(chars[1])) {
139 case 'c':
140 return CSSPrimitiveValue::UnitType::Picas;
141 case 't':
142 return CSSPrimitiveValue::UnitType::Points;
143 case 'x':
144 return CSSPrimitiveValue::UnitType::Pixels;
145 }
146 break;
147 case 'v':
148 switch (toASCIILower(chars[1])) {
149 case 'h':
150 return CSSPrimitiveValue::UnitType::ViewportHeight;
151 case 'w':
152 return CSSPrimitiveValue::UnitType::ViewportWidth;
153 }
154 break;
155 }
156 break;
157 case 3:
158 switch (toASCIILower(chars[0])) {
159 case 'd':
160 switch (toASCIILower(chars[1])) {
161 case 'e':
162 if (toASCIILower(chars[2]) == 'g')
163 return CSSPrimitiveValue::UnitType::Degrees;
164 break;
165 case 'p':
166 if (toASCIILower(chars[2]) == 'i')
167 return CSSPrimitiveValue::UnitType::DotsPerInch;
168 break;
169 }
170 break;
171 case 'k':
172 if (toASCIILower(chars[1]) == 'h' && toASCIILower(chars[2]) == 'z')
173 return CSSPrimitiveValue::UnitType::Kilohertz;
174 break;
175 case 'r':
176 switch (toASCIILower(chars[1])) {
177 case 'a':
178 if (toASCIILower(chars[2]) == 'd')
179 return CSSPrimitiveValue::UnitType::Radians;
180 break;
181 case 'e':
182 if (toASCIILower(chars[2]) == 'm')
183 return CSSPrimitiveValue::UnitType::Rems;
184 break;
185 }
186 break;
187 }
188 break;
189 case 4:
190 // "grad"
191 // "dpcm"
192 // "dppx"
193 // "vmin"
194 // "vmax"
195 // "turns"
196 // TODO(esprehn): Use the trie here too.
197 return unitTable().get(String(chars, length).lower());
198 break;
199 case 5:
200 // "__qem"
Timothy Loh 2016/04/27 06:52:05 this isn't exposed, if it helps we can rename it t
201 // TODO(esprehn): Use the trie here too.
202 return unitTable().get(String(chars, length).lower());
203 break;
204 }
205 return CSSPrimitiveValue::UnitType::Unknown;
206 }
207
89 } // namespace 208 } // namespace
90 209
91 float CSSPrimitiveValue::clampToCSSLengthRange(double value) 210 float CSSPrimitiveValue::clampToCSSLengthRange(double value)
92 { 211 {
93 return clampTo<float>(value, minValueForCssLength, maxValueForCssLength); 212 return clampTo<float>(value, minValueForCssLength, maxValueForCssLength);
94 } 213 }
95 214
96 void CSSPrimitiveValue::initUnitTable() 215 void CSSPrimitiveValue::initUnitTable()
97 { 216 {
98 // Make sure we initialize this during blink initialization 217 // Make sure we initialize this during blink initialization
99 // to avoid racy static local initialization. 218 // to avoid racy static local initialization.
100 unitTable(); 219 unitTable();
101 } 220 }
102 221
103 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit) 222 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
104 { 223 {
105 return unitTable().get(unit.lower()); 224 if (unit.is8Bit())
225 return toUnitType(unit.characters8(), unit.length());
226 return toUnitType(unit.characters16(), unit.length());
227 }
228
229 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const LChar* characters8 , unsigned length)
230 {
231 return toUnitType(characters8, length);
232 }
233
234 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const UChar* characters1 6, unsigned length)
235 {
236 return toUnitType(characters16, length);
106 } 237 }
107 238
108 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitTypeToUnitCategory(UnitTy pe type) 239 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitTypeToUnitCategory(UnitTy pe type)
109 { 240 {
110 switch (type) { 241 switch (type) {
111 case UnitType::Number: 242 case UnitType::Number:
112 return CSSPrimitiveValue::UNumber; 243 return CSSPrimitiveValue::UNumber;
113 case UnitType::Percentage: 244 case UnitType::Percentage:
114 return CSSPrimitiveValue::UPercent; 245 return CSSPrimitiveValue::UPercent;
115 case UnitType::Pixels: 246 case UnitType::Pixels:
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 case UnitType::Calc: 906 case UnitType::Calc:
776 visitor->trace(m_value.calc); 907 visitor->trace(m_value.calc);
777 break; 908 break;
778 default: 909 default:
779 break; 910 break;
780 } 911 }
781 CSSValue::traceAfterDispatch(visitor); 912 CSSValue::traceAfterDispatch(visitor);
782 } 913 }
783 914
784 } // namespace blink 915 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698