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

Side by Side Diff: third_party/WebKit/Source/core/style/StyleVariableData.h

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 #ifndef StyleVariableData_h 5 #ifndef StyleVariableData_h
6 #define StyleVariableData_h 6 #define StyleVariableData_h
7 7
8 #include "core/css/CSSVariableData.h" 8 #include "core/css/CSSVariableData.h"
9 #include "wtf/Forward.h" 9 #include "wtf/Forward.h"
10 #include "wtf/HashMap.h" 10 #include "wtf/HashMap.h"
11 #include "wtf/RefCounted.h" 11 #include "wtf/RefCounted.h"
12 #include "wtf/text/AtomicStringHash.h" 12 #include "wtf/text/AtomicStringHash.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 class StyleVariableData : public RefCounted<StyleVariableData> { 16 class StyleVariableData : public RefCounted<StyleVariableData> {
17 public: 17 public:
18 static PassRefPtr<StyleVariableData> create() { return adoptRef(new StyleVar iableData()); } 18 static PassRefPtr<StyleVariableData> create() { return adoptRef(new StyleVar iableData()); }
19 PassRefPtr<StyleVariableData> copy() const { return adoptRef(new StyleVariab leData(*this)); } 19 PassRefPtr<StyleVariableData> copy();
20 20
21 bool operator==(const StyleVariableData& other) const; 21 bool operator==(const StyleVariableData& other) const;
22 bool operator!=(const StyleVariableData& other) const { return !(*this == ot her); } 22 bool operator!=(const StyleVariableData& other) const { return !(*this == ot her); }
23 23
24 void setVariable(const AtomicString& name, PassRefPtr<CSSVariableData> value ) { m_data.set(name, value); } 24 void setVariable(const AtomicString& name, PassRefPtr<CSSVariableData> value ) { m_data.set(name, value); }
25 CSSVariableData* getVariable(const AtomicString& name) const { return m_data .get(name); } 25 CSSVariableData* getVariable(const AtomicString& name) const;
26 void removeVariable(const AtomicString& name) { return m_data.remove(name); } 26 void removeVariable(const AtomicString& name) { return setVariable(name, nul lptr); }
27 27
28 // This map will contain null pointers if variables are invalid due to 28 // This map will contain null pointers if variables are invalid due to
29 // cycles or referencing invalid variables without using a fallback. 29 // cycles or referencing invalid variables without using a fallback.
30 const HashMap<AtomicString, RefPtr<CSSVariableData>>* getVariables() const { return &m_data; } 30 // Note that this method is slow as a new map is sometimes constructed.
Timothy Loh 2016/04/05 03:13:37 Isn't this always making a new map?
shans 2016/04/08 00:55:49 Uh .. yeah.
31 PassOwnPtr<HashMap<AtomicString, RefPtr<CSSVariableData>>> getVariables() co nst
Timothy Loh 2016/04/05 03:13:37 This function is too big to be in the header, move
shans 2016/04/08 00:55:49 Done.
32 {
33 HashMap<AtomicString, RefPtr<CSSVariableData>>* result;
34 if (m_root) {
35 result = new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_root-> m_data);
36 for (auto it = m_data.begin(); it != m_data.end(); ++it)
37 result->set(it->key, it->value);
38 } else {
39 result = new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_data);
40 }
41 return adoptPtr(result);
42 }
31 private: 43 private:
32 StyleVariableData() = default; 44 StyleVariableData()
Timothy Loh 2016/04/05 03:13:37 this probably didn't need to change, RefPtr's defa
shans 2016/04/08 00:55:49 I changed this because m_root wasn't being initial
Timothy Loh 2016/04/08 03:42:06 :-|
33 StyleVariableData(const StyleVariableData& other) : RefCounted<StyleVariable Data>(), m_data(other.m_data) { } 45 : m_root(nullptr)
46 { }
47 StyleVariableData(StyleVariableData& other);
34 48
35 friend class CSSVariableResolver; 49 friend class CSSVariableResolver;
36 50
37 HashMap<AtomicString, RefPtr<CSSVariableData>> m_data; 51 HashMap<AtomicString, RefPtr<CSSVariableData>> m_data;
52 RefPtr<StyleVariableData> m_root;
38 }; 53 };
39 54
40 } // namespace blink 55 } // namespace blink
41 56
42 #endif // StyleVariableData_h 57 #endif // StyleVariableData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698