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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h

Issue 2897833004: Refactored out need to pass property ID in background list parsing. (Closed)
Patch Set: changed enum to enum class and addressed comments Created 3 years, 7 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
Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
index 08bb57cfc8a5ae117a798c04b12a9fcc80f61d5e..bc2003010609167822e07e270f47ab4ae11bd9ae 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
@@ -112,6 +112,8 @@ bool IsCSSWideKeyword(StringView);
CSSIdentifierValue* ConsumeShapeBox(CSSParserTokenRange&);
+void AddListValueOptimized(CSSValue*& list, CSSValue*);
+
// Template implementations are at the bottom of the file for readability.
template <typename... emptyBaseCase>
@@ -131,22 +133,33 @@ CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) {
return CSSIdentifierValue::Create(range.ConsumeIncludingWhitespace().Id());
}
-// ConsumeCommaSeparatedList takes a callback function to call on each item in
+enum class Optimise { kNo, kYes };
+
+// The first argument to ConsumeCommaSeparatedList indicates whether to optimise
+// the list for memory, such that a single value is returned as it is, instead
+// of being wrapped in a list. Using the optimisation may worsen code health
suzyh_UTC10 (ex-contributor) 2017/06/05 00:49:20 Do we have data to indicate that the optimisation
Bugs Nash 2017/06/05 01:20:50 currently working on that. it seems like it does h
+// as the result needs to be handled for both list and single value cases.
+// The following arguments are a callback function to call on each item in
// the list, followed by the arguments to pass to this callback.
// The first argument to the callback must be the CSSParserTokenRange
template <typename Func, typename... Args>
-CSSValueList* ConsumeCommaSeparatedList(Func callback,
- CSSParserTokenRange& range,
- Args... args) {
- CSSValueList* list = CSSValueList::CreateCommaSeparated();
+CSSValue* ConsumeCommaSeparatedList(Optimise optimise,
+ Func callback,
+ CSSParserTokenRange& range,
+ Args... args) {
+ DCHECK(optimise == Optimise::kNo || optimise == Optimise::kYes);
+ CSSValue* result = nullptr;
+ if (optimise == Optimise::kNo)
+ result = CSSValueList::CreateCommaSeparated();
do {
CSSValue* value = callback(range, args...);
if (!value)
return nullptr;
- list->Append(*value);
+ optimise == Optimise::kYes ? AddListValueOptimized(result, value)
+ : ToCSSValueList(result)->Append(*value);
} while (ConsumeCommaIncludingWhitespace(range));
- DCHECK(list->length());
- return list;
+ DCHECK(!result->IsBaseValueList() || ToCSSValueList(result)->length());
+ return result;
}
} // namespace CSSPropertyParserHelpers

Powered by Google App Engine
This is Rietveld 408576698