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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/style/StyleVariableData.h" 5 #include "core/style/StyleVariableData.h"
6 6
7 #include "core/style/DataEquivalency.h" 7 #include "core/style/DataEquivalency.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 bool StyleVariableData::operator==(const StyleVariableData& other) const 11 bool StyleVariableData::operator==(const StyleVariableData& other) const
12 { 12 {
13 if (m_data.size() != other.m_data.size()) { 13 // It's technically possible for divergent roots to be value-equal,
14 // but unlikely. This equality operator is used for optimization purposes
15 // so it's OK to be occasionally wrong.
16 // TODO(shanestephens): Rename this to something that indicates it may not
17 // always return equality.
18 if (m_root != other.m_root)
14 return false; 19 return false;
15 } 20
21 if (m_data.size() != other.m_data.size())
22 return false;
16 23
17 for (const auto& iter : m_data) { 24 for (const auto& iter : m_data) {
18 RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key); 25 RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key);
19 if (!dataEquivalent(iter.value, otherData)) 26 if (!dataEquivalent(iter.value, otherData))
20 return false; 27 return false;
21 } 28 }
22 29
23 return true; 30 return true;
24 } 31 }
25 32
33 PassRefPtr<StyleVariableData> StyleVariableData::copy()
34 {
35 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.
36 }
37
38 StyleVariableData::StyleVariableData(StyleVariableData& other)
39 {
40 if (!other.m_root) {
41 m_root = &other;
42 } else {
43 m_data = other.m_data;
44 m_root = other.m_root;
45 }
46 }
47
Timothy Loh 2016/04/05 03:13:37 extra whitespace here
shans 2016/04/08 00:55:49 Done.
48
49 CSSVariableData* StyleVariableData::getVariable(const AtomicString& name) const
50 {
51 auto result = m_data.find(name);
52 if (result == m_data.end() && m_root)
53 return m_root->getVariable(name);
54 if (result == m_data.end())
55 return nullptr;
56 return result->value.get();
57 }
58
59
Timothy Loh 2016/04/05 03:13:37 more extra whitespace here
shans 2016/04/08 00:55:49 Done.
60
26 } // namespace blink 61 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698