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

Unified Diff: Source/core/css/parser/CSSParserFastPaths.cpp

Issue 1196533002: Clean up fast path CSS color parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/parser/CSSParserFastPaths.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/parser/CSSParserFastPaths.cpp
diff --git a/Source/core/css/parser/CSSParserFastPaths.cpp b/Source/core/css/parser/CSSParserFastPaths.cpp
index 74507859e75ac53f804fbf08add1dc44fc2892e3..5acbbab07b0db11e5b05c88526471319eb90af19 100644
--- a/Source/core/css/parser/CSSParserFastPaths.cpp
+++ b/Source/core/css/parser/CSSParserFastPaths.cpp
@@ -428,31 +428,7 @@ static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters,
return false;
}
-bool CSSParserFastPaths::parseColorAsRGBA32(RGBA32& rgb, const String& name, bool quirksMode)
-{
- unsigned length = name.length();
- bool parseResult;
-
- if (!length)
- return false;
-
- if (name.is8Bit())
- parseResult = fastParseColorInternal(rgb, name.characters8(), length, quirksMode);
- else
- parseResult = fastParseColorInternal(rgb, name.characters16(), length, quirksMode);
-
- if (parseResult)
- return true;
-
- // Try named colors.
- Color tc;
- if (!tc.setNamedColor(name))
- return false;
- rgb = tc.rgb();
- return true;
-}
-
-static PassRefPtrWillBeRawPtr<CSSValue> parseColor(const String& string, bool quirksMode)
+PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, bool quirksMode)
{
ASSERT(!string.isEmpty());
CSSParserString cssString;
@@ -464,9 +440,20 @@ static PassRefPtrWillBeRawPtr<CSSValue> parseColor(const String& string, bool qu
return cssValuePool().createIdentifierValue(valueID);
RGBA32 color;
- if (!CSSParserFastPaths::parseColorAsRGBA32(color, string, quirksMode))
+
+ // Fast path for hex colors and rgb()/rgba() colors
+ bool parseResult;
+ if (string.is8Bit())
+ parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode);
+ else
+ parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode);
+ if (parseResult)
+ return cssValuePool().createColorValue(color);
+
+ Color namedColor;
+ if (!namedColor.setNamedColor(string))
return nullptr;
- return cssValuePool().createColorValue(color);
+ return cssValuePool().createColorValue(namedColor.rgb());
}
bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId, CSSValueID valueID)
« no previous file with comments | « Source/core/css/parser/CSSParserFastPaths.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698