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

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

Issue 1182433002: Use lambda instead of the 'CSSPropertyIDComparer' class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 65c8e1f4d8c7bc7071d79c3b6d40990cd749a944..904c8159e852d4f1313e0557b4a4c0381b0b057f 100644
--- a/Source/core/css/StylePropertySet.cpp
+++ b/Source/core/css/StylePropertySet.cpp
@@ -500,31 +500,25 @@ CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
return m_cssomWrapper.get();
}
+int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
+{
+ const CSSProperty* begin = m_propertyVector.data();
+ const CSSProperty* end = begin + m_propertyVector.size();
+ // 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);
-class CSSPropertyIDComparer {
-public:
- explicit CSSPropertyIDComparer(CSSPropertyID propertyID)
- : m_propertyID(static_cast<uint16_t>(propertyID)) { }
- bool operator()(const CSSProperty& property) const
+ auto compare = [propertyID, id](const CSSProperty& property) -> bool
{
- if (property.metadata().m_propertyID == m_propertyID) {
+ if (property.metadata().m_propertyID == id) {
// Only enabled properties should be part of the style.
- ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID()));
+ ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
return true;
}
return false;
- }
-
-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));
+ const CSSProperty* it = std::find_if(begin, end, compare);
return (it == end) ? -1 : it - begin;
}
« 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