diff --git a/bridge/core/css/css_value_pool.cc b/bridge/core/css/css_value_pool.cc index fc9f6a9e4..5941288ca 100644 --- a/bridge/core/css/css_value_pool.cc +++ b/bridge/core/css/css_value_pool.cc @@ -31,6 +31,13 @@ namespace webf { +CSSValuePool::CSSValuePool() { + identifier_value_cache_.reserve(kMaximumCacheableIntegerValue); + pixel_value_cache_.reserve(kMaximumCacheableIntegerValue); + percent_value_cache_.reserve(kMaximumCacheableIntegerValue); + number_value_cache_.reserve(kMaximumCacheableIntegerValue); +} + CSSValuePool& CssValuePool() { thread_local static CSSValuePool pool; return pool; diff --git a/bridge/core/css/css_value_pool.h b/bridge/core/css/css_value_pool.h index b0cd7ef1a..ef63e4a85 100644 --- a/bridge/core/css/css_value_pool.h +++ b/bridge/core/css/css_value_pool.h @@ -57,6 +57,8 @@ class CSSValuePool { public: using PassKey = webf::PassKey; + CSSValuePool(); + static const int kMaximumCacheableIntegerValue = 255; using CSSColor = cssvalue::CSSColor; using CSSUnsetValue = cssvalue::CSSUnsetValue; @@ -80,21 +82,20 @@ class CSSValuePool { // CSSValuePool& operator=(const CSSValuePool&) = delete; // // // Cached individual values. - std::shared_ptr TransparentColor() const { return color_transparent_; } - std::shared_ptr WhiteColor() const { return color_white_; } - std::shared_ptr BlackColor() const { return color_black_; } - std::shared_ptr InheritedValue() { return inherited_value_; } - std::shared_ptr InitialValue() const { return initial_value_; } - std::shared_ptr InitialSharedPointerValue() const { return initial_value_; } - std::shared_ptr const UnsetValue() { return unset_value_; } - std::shared_ptr const RevertValue() { return revert_value_; } - std::shared_ptr const RevertLayerValue() { return revert_layer_value_; } - std::shared_ptr const InvalidVariableValue() { return invalid_variable_value_; } -// CSSCyclicVariableValue* CyclicVariableValue() { return cyclic_variable_value_.get(); } - std::shared_ptr const InitialColorValue() { return initial_color_value_; } + const std::shared_ptr& TransparentColor() const { return color_transparent_; } + const std::shared_ptr& WhiteColor() const { return color_white_; } + const std::shared_ptr& BlackColor() const { return color_black_; } + const std::shared_ptr& InheritedValue() { return inherited_value_; } + const std::shared_ptr& InitialValue() const { return initial_value_; } + const std::shared_ptr& InitialSharedPointerValue() const { return initial_value_; } + const std::shared_ptr& UnsetValue() { return unset_value_; } + const std::shared_ptr& RevertValue() { return revert_value_; } + const std::shared_ptr& RevertLayerValue() { return revert_layer_value_; } + const std::shared_ptr& InvalidVariableValue() { return invalid_variable_value_; } + const std::shared_ptr& InitialColorValue() { return initial_color_value_; } // Vector caches. - std::shared_ptr IdentifierCacheValue(CSSValueID ident) { + const std::shared_ptr& IdentifierCacheValue(CSSValueID ident) { return identifier_value_cache_[static_cast(ident)]; } std::shared_ptr SetIdentifierCacheValue( @@ -183,7 +184,6 @@ class CSSValuePool { std::shared_ptr revert_value_; std::shared_ptr revert_layer_value_; std::shared_ptr invalid_variable_value_; -// Member cyclic_variable_value_; std::shared_ptr initial_color_value_; std::shared_ptr color_transparent_; std::shared_ptr color_white_; diff --git a/bridge/core/css/parser/css_parser_impl.cc b/bridge/core/css/parser/css_parser_impl.cc index 9957366af..45d48280b 100644 --- a/bridge/core/css/parser/css_parser_impl.cc +++ b/bridge/core/css/parser/css_parser_impl.cc @@ -871,7 +871,7 @@ void CSSParserImpl::ConsumeDeclarationValue(CSSParserTokenStream& stream, StyleRule::RuleType rule_type) { const bool allow_important_annotation = is_in_declaration_list && rule_type != StyleRule::kKeyframe && rule_type != StyleRule::kPositionTry; - CSSPropertyParser::ParseValue(unresolved_property, allow_important_annotation, stream, context_.get(), + CSSPropertyParser::ParseValue(unresolved_property, allow_important_annotation, stream, context_, parsed_properties_, rule_type); } diff --git a/bridge/core/css/parser/css_property_parser.cc b/bridge/core/css/parser/css_property_parser.cc index e2e8a1690..9df0b9a60 100644 --- a/bridge/core/css/parser/css_property_parser.cc +++ b/bridge/core/css/parser/css_property_parser.cc @@ -49,7 +49,7 @@ bool IsPropertyAllowedInRule(const CSSProperty& property, StyleRule::RuleType ru } // namespace CSSPropertyParser::CSSPropertyParser(CSSParserTokenStream& stream, - const CSSParserContext* context, + std::shared_ptr context, std::vector* parsed_properties) : stream_(stream), context_(context), parsed_properties_(parsed_properties) { // Strip initial whitespace/comments from stream_. @@ -218,7 +218,7 @@ bool CSSPropertyParser::ParseValueStart(webf::CSSPropertyID unresolved_property, bool CSSPropertyParser::ParseValue(CSSPropertyID unresolved_property, bool allow_important_annotation, CSSParserTokenStream& stream, - const CSSParserContext* context, + std::shared_ptr context, std::vector& parsed_properties, StyleRule::RuleType rule_type) { CSSPropertyParser parser(stream, context, &parsed_properties); diff --git a/bridge/core/css/parser/css_property_parser.h b/bridge/core/css/parser/css_property_parser.h index 1057666b7..71e111e0d 100644 --- a/bridge/core/css/parser/css_property_parser.h +++ b/bridge/core/css/parser/css_property_parser.h @@ -65,7 +65,7 @@ class CSSPropertyParser { static bool ParseValue(CSSPropertyID, bool allow_important_annotation, CSSParserTokenStream&, - const CSSParserContext*, + std::shared_ptr, std::vector&, StyleRule::RuleType); @@ -85,7 +85,7 @@ class CSSPropertyParser { private: CSSPropertyParser(CSSParserTokenStream&, - const CSSParserContext*, + std::shared_ptr, std::vector*); // TODO(timloh): Rename once the CSSParserValue-based parseValue is removed diff --git a/bridge/core/css/style_element.cc b/bridge/core/css/style_element.cc index 5fd4fed17..10e8052c0 100644 --- a/bridge/core/css/style_element.cc +++ b/bridge/core/css/style_element.cc @@ -106,7 +106,7 @@ StyleElement::ProcessingResult StyleElement::CreateSheet(Element& element, const loading_ = true; - auto* new_sheet = document.EnsureStyleEngine().CreateSheet(element, text);// + auto* new_sheet = document.EnsureStyleEngine().CreateSheet(element, text); sheet_ = new_sheet; return kProcessingSuccessful;