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

Unified Diff: Source/core/css/StylePropertySet.cpp

Issue 1167383004: Optimize MutableStylePropertySet::findPropertyIndex (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix debug build Created 5 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/StylePropertySet.cpp
diff --git a/Source/core/css/StylePropertySet.cpp b/Source/core/css/StylePropertySet.cpp
index d0da61710b52cdd6d624c5a5fc789e20ce727e02..65c8e1f4d8c7bc7071d79c3b6d40990cd749a944 100644
--- a/Source/core/css/StylePropertySet.cpp
+++ b/Source/core/css/StylePropertySet.cpp
@@ -500,21 +500,33 @@ CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
return m_cssomWrapper.get();
}
-int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
-{
- // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid
- // the compiler converting it to an int multiple times in the loop.
- uint16_t id = static_cast<uint16_t>(propertyID);
- const CSSProperty* properties = m_propertyVector.data();
- for (int n = m_propertyVector.size() - 1 ; n >= 0; --n) {
- if (properties[n].metadata().m_propertyID == id) {
+
+class CSSPropertyIDComparer {
+public:
+ explicit CSSPropertyIDComparer(CSSPropertyID propertyID)
+ : m_propertyID(static_cast<uint16_t>(propertyID)) { }
+ bool operator()(const CSSProperty& property) const
+ {
+ if (property.metadata().m_propertyID == m_propertyID) {
// Only enabled properties should be part of the style.
- ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
- return n;
+ ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID()));
+ return true;
}
+ return false;
}
- return -1;
+private:
+ CSSPropertyID propertyID() const { return static_cast<CSSPropertyID>(m_propertyID); }
+ uint16_t m_propertyID; // Store as uint16_t to avoid casts while comparing.
+};
+
+int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
+{
+ const CSSProperty* begin = m_propertyVector.data();
+ const CSSProperty* end = begin + m_propertyVector.size();
+ const CSSProperty* it = std::find_if(begin, end, CSSPropertyIDComparer(propertyID));
+
+ return (it == end) ? -1 : it - begin;
}
DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698