Modified: trunk/Source/WebCore/ChangeLog (103638 => 103639)
--- trunk/Source/WebCore/ChangeLog 2011-12-23 21:36:59 UTC (rev 103638)
+++ trunk/Source/WebCore/ChangeLog 2011-12-23 22:33:58 UTC (rev 103639)
@@ -1,3 +1,25 @@
+2011-12-22 Andreas Kling <[email protected]>
+
+ CSSParser: Avoid creating dummy declaration in parseColor() slow path.
+ <http://webkit.org/b/75104>
+
+ Reviewed by Darin Adler.
+
+ We only needed the dummy declaration to trigger the instantiation of
+ a CSSValuePool. Added an ensureCSSValuePool() method and have parseColor()
+ call that instead.
+
+ Also renamed the fast-path parseColor() to fastParseColor() and reordered
+ the arguments for consistency with the slow-path parseColor().
+
+ * css/CSSParser.cpp:
+ (WebCore::parseColorValue):
+ (WebCore::CSSParser::parseColor):
+ (WebCore::CSSParser::ensureCSSValuePool):
+ (WebCore::CSSParser::fastParseColor):
+ (WebCore::CSSParser::parseColorFromValue):
+ * css/CSSParser.h:
+
2011-12-21 Andreas Kling <[email protected]>
Automate elements' registration as document namedItem/extraNamedItem.
Modified: trunk/Source/WebCore/css/CSSParser.cpp (103638 => 103639)
--- trunk/Source/WebCore/css/CSSParser.cpp 2011-12-23 21:36:59 UTC (rev 103638)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2011-12-23 22:33:58 UTC (rev 103639)
@@ -171,6 +171,12 @@
return false;
}
+inline void CSSParser::ensureCSSValuePool()
+{
+ if (!m_cssValuePool)
+ m_cssValuePool = CSSValuePool::create();
+}
+
CSSParser::CSSParser(bool strictParsing)
: m_strict(strictParsing)
, m_important(false)
@@ -358,7 +364,7 @@
return true;
}
RGBA32 color;
- if (!CSSParser::parseColor(string, color, strict && string[0] != '#'))
+ if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
return false;
CSSProperty property(propertyId, document->cssValuePool()->createColorValue(color), important);
declaration->addParsedProperty(property);
@@ -494,14 +500,13 @@
bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
{
// First try creating a color specified by name, rgba(), rgb() or "#" syntax.
- if (parseColor(string, color, strict))
+ if (fastParseColor(color, string, strict))
return true;
CSSParser parser(true);
- RefPtr<CSSMutableStyleDeclaration> dummyStyleDeclaration = CSSMutableStyleDeclaration::create();
- // Now try to create a color from rgba() syntax.
- if (!parser.parseColor(dummyStyleDeclaration.get(), string))
+ // In case the fast-path parser didn't understand the color, try the full parser.
+ if (!parser.parseColor(string))
return false;
CSSValue* value = parser.m_parsedProperties[0]->value();
@@ -516,9 +521,11 @@
return true;
}
-bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String& string)
+bool CSSParser::parseColor(const String& string)
{
- setStyleSheet(declaration->parentStyleSheet());
+ // This function may be called without a stylesheet set on the parser, so we need to
+ // make sure that we have a CSSValuePool or we'll crash below cssyyparse().
+ ensureCSSValuePool();
setupParser("@-webkit-decls{color:", string, "} ");
cssyyparse(this);
@@ -4765,7 +4772,7 @@
&& (characters[2] | 0x20) == 'b';
}
-bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict)
+bool CSSParser::fastParseColor(RGBA32& rgb, const String& name, bool strict)
{
const UChar* characters = name.characters();
unsigned length = name.length();
@@ -4934,12 +4941,12 @@
if (!m_strict && value->unit == CSSPrimitiveValue::CSS_NUMBER &&
value->fValue >= 0. && value->fValue < 1000000.) {
String str = String::format("%06d", static_cast<int>((value->fValue+.5)));
- if (!CSSParser::parseColor(str, c, m_strict))
+ if (!fastParseColor(c, str, m_strict))
return false;
} else if (value->unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR ||
value->unit == CSSPrimitiveValue::CSS_IDENT ||
(!m_strict && value->unit == CSSPrimitiveValue::CSS_DIMENSION)) {
- if (!CSSParser::parseColor(value->string, c, m_strict && value->unit == CSSPrimitiveValue::CSS_IDENT))
+ if (!fastParseColor(c, value->string, m_strict && value->unit == CSSPrimitiveValue::CSS_IDENT))
return false;
} else if (value->unit == CSSParserValue::Function &&
value->function->args != 0 &&
Modified: trunk/Source/WebCore/css/CSSParser.h (103638 => 103639)
--- trunk/Source/WebCore/css/CSSParser.h 2011-12-23 21:36:59 UTC (rev 103638)
+++ trunk/Source/WebCore/css/CSSParser.h 2011-12-23 22:33:58 UTC (rev 103639)
@@ -69,7 +69,6 @@
static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool parseSystemColor(RGBA32& color, const String&, Document*);
PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int propId, CSSParserValue*);
- bool parseColor(CSSMutableStyleDeclaration*, const String&);
bool parseDeclaration(CSSMutableStyleDeclaration*, const String&, RefPtr<CSSStyleSourceData>* = 0, CSSStyleSheet* contextStyleSheet = 0);
bool parseMediaQuery(MediaList*, const String&);
@@ -151,7 +150,7 @@
bool parseColorFromValue(CSSParserValue*, RGBA32&);
void parseSelector(const String&, Document* doc, CSSSelectorList&);
- static bool parseColor(const String&, RGBA32& rgb, bool strict);
+ static bool fastParseColor(RGBA32&, const String&, bool strict);
bool parseFontStyle(bool important);
bool parseFontVariant(bool important);
@@ -317,6 +316,7 @@
private:
void setStyleSheet(CSSStyleSheet*);
+ void ensureCSSValuePool();
void recheckAtKeyword(const UChar* str, int len);
@@ -348,6 +348,8 @@
bool parseFontFaceSrcURI(CSSValueList*);
bool parseFontFaceSrcLocal(CSSValueList*);
+ bool parseColor(const String&);
+
UChar* m_data;
UChar* yytext;
UChar* yy_c_buf_p;