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

Unified Diff: third_party/WebKit/Source/core/style/StyleVariableData.cpp

Issue 1858553002: Refactor StyleVariableData to fallback on root map for performance reasons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
Index: third_party/WebKit/Source/core/style/StyleVariableData.cpp
diff --git a/third_party/WebKit/Source/core/style/StyleVariableData.cpp b/third_party/WebKit/Source/core/style/StyleVariableData.cpp
index c00080d7a2ec3a870346d210a671f2556845a996..17759b755456a6cf3152d825ffe2d5e6a8993266 100644
--- a/third_party/WebKit/Source/core/style/StyleVariableData.cpp
+++ b/third_party/WebKit/Source/core/style/StyleVariableData.cpp
@@ -10,9 +10,16 @@ namespace blink {
bool StyleVariableData::operator==(const StyleVariableData& other) const
{
- if (m_data.size() != other.m_data.size()) {
+ // It's technically possible for divergent roots to be value-equal,
+ // but unlikely. This equality operator is used for optimization purposes
+ // so it's OK to be occasionally wrong.
+ // TODO(shanestephens): Rename this to something that indicates it may not
+ // always return equality.
+ if (m_root != other.m_root)
+ return false;
+
+ if (m_data.size() != other.m_data.size())
return false;
- }
for (const auto& iter : m_data) {
RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key);
@@ -23,4 +30,32 @@ bool StyleVariableData::operator==(const StyleVariableData& other) const
return true;
}
+PassRefPtr<StyleVariableData> StyleVariableData::copy()
+{
+ return adoptRef(new StyleVariableData(*this));
Timothy Loh 2016/04/05 03:13:37 No point moving this if it didn't change
shans 2016/04/08 00:55:49 Done.
+}
+
+StyleVariableData::StyleVariableData(StyleVariableData& other)
+{
+ if (!other.m_root) {
+ m_root = &other;
+ } else {
+ m_data = other.m_data;
+ m_root = other.m_root;
+ }
+}
+
Timothy Loh 2016/04/05 03:13:37 extra whitespace here
shans 2016/04/08 00:55:49 Done.
+
+CSSVariableData* StyleVariableData::getVariable(const AtomicString& name) const
+{
+ auto result = m_data.find(name);
+ if (result == m_data.end() && m_root)
+ return m_root->getVariable(name);
+ if (result == m_data.end())
+ return nullptr;
+ return result->value.get();
+}
+
+
Timothy Loh 2016/04/05 03:13:37 more extra whitespace here
shans 2016/04/08 00:55:49 Done.
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698