Chromium Code Reviews| 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 |