Commit f966e0ed authored by Hans Wennborg's avatar Hans Wennborg Committed by Commit Bot

CSSProperty: Use member variables to store static characteristics

instead of costly virtual functions.

This saves on code size, data size, number of dynamic relocations, and makes
accessing these properties faster.

Bug: none
Change-Id: I1750f8d8e03c1ff4925a86778c6f65ae7125a566
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538527
Commit-Queue: Hans Wennborg <hans@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645292}
parent 51c07568
...@@ -29,8 +29,35 @@ class {{property_classname}} final : public CSSUnresolvedProperty { ...@@ -29,8 +29,35 @@ class {{property_classname}} final : public CSSUnresolvedProperty {
{% else %} {% else %}
class {{property_classname}} final : public {{property.namespace_group}} { class {{property_classname}} final : public {{property.namespace_group}} {
public: public:
constexpr {{property_classname}}() : {{property.namespace_group}}() {} constexpr {{property_classname}}() : {{property.namespace_group}}(CSSPropertyID::{{property.enum_key}},
0
{% if property.interpolable %}
| kInterpolable
{% endif %}
{% if property.compositable %}
| kCompositableProperty
{% endif %}
{% if property.is_descriptor %}
| kDescriptor
{% endif %}
{% if 'Percent' in property.typedom_types %}
| kSupportsPercentage
{% endif %}
{% if property.is_property %}
| kProperty
{% endif %}
{% if property.valid_for_visited_link %}
| kValidForVisitedLink
{% endif %}
,
{% if property.separator != None %}
'{{property.separator}}'
{% else %}
'\0'
{% endif %} {% endif %}
) {}
{% endif %}
{% if property.is_internal %} {% if property.is_internal %}
bool IsEnabled() const override { return false; } bool IsEnabled() const override { return false; }
{% elif property.runtime_flag %} {% elif property.runtime_flag %}
...@@ -47,7 +74,6 @@ class {{property_classname}} final : public {{property.namespace_group}} { ...@@ -47,7 +74,6 @@ class {{property_classname}} final : public {{property.namespace_group}} {
return "{{property_classname[0].lower() + property_classname[1:]}}"; return "{{property_classname[0].lower() + property_classname[1:]}}";
} }
{% if property.alias_for == None %} {% if property.alias_for == None %}
CSSPropertyID PropertyID() const override { return CSSPropertyID::{{property.enum_key}}; }
{%if property.layout_dependent %} {%if property.layout_dependent %}
bool IsLayoutDependentProperty() const override { return true; } bool IsLayoutDependentProperty() const override { return true; }
bool IsLayoutDependent(const ComputedStyle*, LayoutObject*) const override; bool IsLayoutDependent(const ComputedStyle*, LayoutObject*) const override;
...@@ -55,34 +81,14 @@ class {{property_classname}} final : public {{property.namespace_group}} { ...@@ -55,34 +81,14 @@ class {{property_classname}} final : public {{property.namespace_group}} {
{% for property_method in property.property_methods %} {% for property_method in property.property_methods %}
{{property_method.return_type}} {{property_method.name}}{{property_method.parameters}} const override; {{property_method.return_type}} {{property_method.name}}{{property_method.parameters}} const override;
{% endfor %} {% endfor %}
{% if property.interpolable %}
bool IsInterpolable() const override { return true; }
{% endif %}
{% if property.inherited %} {% if property.inherited %}
bool IsInherited() const override { return true; } bool IsInherited() const override { return true; }
{% endif %} {% endif %}
{% if property.compositable %}
bool IsCompositableProperty() const override { return true; }
{% endif %}
{% if property.separator != None %} {% if property.separator != None %}
bool IsRepeated() const override { return true; }
char RepetitionSeparator() const override { return '{{property.separator}}'; }
{% endif %}
{% if property.is_descriptor %}
bool IsDescriptor() const override { return true; }
{% endif %}
{% if 'Percent' in property.typedom_types %}
bool SupportsPercentage() const override { return true; }
{% endif %}
{% if not property.is_property %}
bool IsProperty() const override { return false; }
{% endif %} {% endif %}
{% if not property.affected_by_all %} {% if not property.affected_by_all %}
bool IsAffectedByAll() const override { return false; } bool IsAffectedByAll() const override { return false; }
{% endif %} {% endif %}
{% if property.valid_for_visited_link %}
bool IsValidForVisitedLink() const override { return true; }
{% endif %}
{% if property.direction_aware_options %} {% if property.direction_aware_options %}
const CSSValue* CSSValueFromComputedStyleInternal( const CSSValue* CSSValueFromComputedStyleInternal(
const ComputedStyle& , const ComputedStyle& ,
......
...@@ -32,33 +32,34 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty { ...@@ -32,33 +32,34 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty {
// For backwards compatibility when passing around CSSUnresolvedProperty // For backwards compatibility when passing around CSSUnresolvedProperty
// references. In case we need to call a function that hasn't been converted // references. In case we need to call a function that hasn't been converted
// to using property classes yet. // to using property classes yet.
virtual CSSPropertyID PropertyID() const { CSSPropertyID PropertyID() const { return property_id_; }
NOTREACHED();
return CSSPropertyID::kInvalid;
}
virtual CSSPropertyName GetCSSPropertyName() const { virtual CSSPropertyName GetCSSPropertyName() const {
return CSSPropertyName(PropertyID()); return CSSPropertyName(PropertyID());
} }
bool IDEquals(CSSPropertyID id) const { return PropertyID() == id; } bool IDEquals(CSSPropertyID id) const { return PropertyID() == id; }
bool IsResolvedProperty() const override { return true; } bool IsResolvedProperty() const override { return true; }
virtual bool IsInterpolable() const { return false; }
bool IsInterpolable() const { return flags_ & kInterpolable; }
bool IsCompositableProperty() const { return flags_ & kCompositableProperty; }
bool IsDescriptor() const { return flags_ & kDescriptor; }
bool SupportsPercentage() const { return flags_ & kSupportsPercentage; }
bool IsProperty() const { return flags_ & kProperty; }
bool IsValidForVisitedLink() const { return flags_ & kValidForVisitedLink; }
bool IsShorthand() const { return flags_ & kShorthand; }
bool IsLonghand() const { return flags_ & kLonghand; }
bool IsRepeated() const { return repetition_separator_ != '\0'; }
char RepetitionSeparator() const { return repetition_separator_; }
virtual bool IsInherited() const { return false; } virtual bool IsInherited() const { return false; }
virtual bool IsCompositableProperty() const { return false; }
virtual bool IsRepeated() const { return false; }
virtual char RepetitionSeparator() const {
NOTREACHED();
return 0;
}
virtual bool IsDescriptor() const { return false; }
virtual bool SupportsPercentage() const { return false; }
virtual bool IsProperty() const { return true; }
virtual bool IsAffectedByAll() const { return IsEnabled() && IsProperty(); } virtual bool IsAffectedByAll() const { return IsEnabled() && IsProperty(); }
virtual bool IsLayoutDependentProperty() const { return false; } virtual bool IsLayoutDependentProperty() const { return false; }
virtual bool IsLayoutDependent(const ComputedStyle* style, virtual bool IsLayoutDependent(const ComputedStyle* style,
LayoutObject* layout_object) const { LayoutObject* layout_object) const {
return false; return false;
} }
virtual bool IsValidForVisitedLink() const { return false; }
virtual const CSSValue* CSSValueFromComputedStyleInternal( virtual const CSSValue* CSSValueFromComputedStyleInternal(
const ComputedStyle&, const ComputedStyle&,
...@@ -83,14 +84,29 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty { ...@@ -83,14 +84,29 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty {
WritingMode) const { WritingMode) const {
return *this; return *this;
} }
virtual bool IsShorthand() const { return false; }
virtual bool IsLonghand() const { return false; }
static void FilterEnabledCSSPropertiesIntoVector(const CSSPropertyID*, static void FilterEnabledCSSPropertiesIntoVector(const CSSPropertyID*,
size_t length, size_t length,
Vector<const CSSProperty*>&); Vector<const CSSProperty*>&);
protected: protected:
constexpr CSSProperty() : CSSUnresolvedProperty() {} enum Flag : uint8_t {
kInterpolable = 1 << 0,
kCompositableProperty = 1 << 1,
kDescriptor = 1 << 2,
kSupportsPercentage = 1 << 3,
kProperty = 1 << 4,
kValidForVisitedLink = 1 << 5,
kShorthand = 1 << 6,
kLonghand = 1 << 7
};
constexpr CSSProperty(CSSPropertyID property_id,
uint8_t flags,
char repetition_separator)
: CSSUnresolvedProperty(),
property_id_(property_id),
flags_(flags),
repetition_separator_(repetition_separator) {}
static const StylePropertyShorthand& BorderDirections(); static const StylePropertyShorthand& BorderDirections();
static const CSSProperty& ResolveAfterToPhysicalProperty( static const CSSProperty& ResolveAfterToPhysicalProperty(
...@@ -109,6 +125,11 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty { ...@@ -109,6 +125,11 @@ class CORE_EXPORT CSSProperty : public CSSUnresolvedProperty {
TextDirection, TextDirection,
WritingMode, WritingMode,
const StylePropertyShorthand&); const StylePropertyShorthand&);
private:
CSSPropertyID property_id_;
uint8_t flags_;
char repetition_separator_;
}; };
template <> template <>
......
...@@ -38,13 +38,13 @@ class Longhand : public CSSProperty { ...@@ -38,13 +38,13 @@ class Longhand : public CSSProperty {
NOTREACHED(); NOTREACHED();
return Color(); return Color();
} }
bool IsLonghand() const override { return true; }
virtual const CSSValue* InitialValue() const { virtual const CSSValue* InitialValue() const {
return CSSInitialValue::Create(); return CSSInitialValue::Create();
} }
protected: protected:
constexpr Longhand() : CSSProperty() {} constexpr Longhand(CSSPropertyID id, uint8_t flags, char repetition_separator)
: CSSProperty(id, flags | kLonghand, repetition_separator) {}
}; };
template <> template <>
......
...@@ -17,11 +17,10 @@ namespace blink { ...@@ -17,11 +17,10 @@ namespace blink {
// (as returned by GetCSSPropertyVariable()) has been removed. // (as returned by GetCSSPropertyVariable()) has been removed.
class CORE_EXPORT Variable : public Longhand { class CORE_EXPORT Variable : public Longhand {
public: public:
constexpr Variable() : Longhand() {} constexpr Variable() : Longhand(CSSPropertyID::kVariable, kProperty, '\0') {}
bool IsInherited() const override { return true; } bool IsInherited() const override { return true; }
bool IsAffectedByAll() const override { return false; } bool IsAffectedByAll() const override { return false; }
CSSPropertyID PropertyID() const override { return CSSPropertyID::kVariable; }
CSSPropertyName GetCSSPropertyName() const override { CSSPropertyName GetCSSPropertyName() const override {
NOTREACHED(); NOTREACHED();
return CSSPropertyName(""); return CSSPropertyName("");
......
...@@ -29,10 +29,12 @@ class Shorthand : public CSSProperty { ...@@ -29,10 +29,12 @@ class Shorthand : public CSSProperty {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
bool IsShorthand() const override { return true; }
protected: protected:
constexpr Shorthand() : CSSProperty() {} constexpr Shorthand(CSSPropertyID id,
uint8_t flags,
char repetition_separator)
: CSSProperty(id, flags | kShorthand, repetition_separator) {}
}; };
template <> template <>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment