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

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

Issue 2891973004: WIP Add memory optimisation option to ConsumeCommaSeparatedList (Closed)
Patch Set: fixed dcheck bug 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
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e1f2a5f6a246ddc69af242a03f058341d0602292..7e070a72d51db27d7d718e4691431ece5fe381d6 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.h
@@ -126,18 +126,35 @@ CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) {
// 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(bool optimise,
+ Func callback,
+ CSSParserTokenRange& range,
+ Args... args) {
+ CSSValue* result = nullptr;
+ if (!optimise)
+ result = CSSValueList::CreateCommaSeparated();
do {
CSSValue* value = callback(range, args...);
if (!value)
return nullptr;
- list->Append(*value);
+
+ if (optimise) {
+ if (!result) {
+ // To conserve memory we don't wrap a single value in a list.
+ result = value;
+ continue;
+ }
+ if (!result->IsBaseValueList()) {
+ CSSValue* first_value = result;
+ result = CSSValueList::CreateCommaSeparated();
+ ToCSSValueList(result)->Append(*first_value);
+ }
+ }
+ ToCSSValueList(result)->Append(*value);
} while (ConsumeCommaIncludingWhitespace(range));
- DCHECK(list->length());
- return list;
+
+ DCHECK(!result->IsBaseValueList() || ToCSSValueList(result)->length());
+ return result;
}
} // namespace CSSPropertyParserHelpers
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698