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

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
« no previous file with comments | « third_party/WebKit/Source/core/style/StyleVariableData.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 StyleVariableData::StyleVariableData(StyleVariableData& other)
34 {
35 if (!other.m_root) {
36 m_root = &other;
37 } else {
38 m_data = other.m_data;
39 m_root = other.m_root;
40 }
41 }
42
43 CSSVariableData* StyleVariableData::getVariable(const AtomicString& name) const
44 {
45 auto result = m_data.find(name);
46 if (result == m_data.end() && m_root)
47 return m_root->getVariable(name);
48 if (result == m_data.end())
49 return nullptr;
50 return result->value.get();
51 }
52
53 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> StyleVariableDat a::getVariables() const
54 {
55 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> result;
56 if (m_root) {
57 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_root-> m_data));
58 for (auto it = m_data.begin(); it != m_data.end(); ++it)
59 result->set(it->key, it->value);
60 } else {
61 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_data)) ;
62 }
63 return result;
64 }
65
26 } // namespace blink 66 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/StyleVariableData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698