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

Side by Side Diff: sky/engine/core/css/resolver/MatchedPropertiesCache.cpp

Issue 681963002: Remove heap/*.cpp files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 17 matching lines...) Expand all
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/MatchedPropertiesCache.h" 30 #include "core/css/resolver/MatchedPropertiesCache.h"
31 31
32 #include "core/css/StylePropertySet.h" 32 #include "core/css/StylePropertySet.h"
33 #include "core/css/resolver/StyleResolverState.h" 33 #include "core/css/resolver/StyleResolverState.h"
34 #include "core/rendering/style/RenderStyle.h" 34 #include "core/rendering/style/RenderStyle.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 #if ENABLE(OILPAN)
39 bool CachedMatchedPropertiesHashTraits::traceInCollection(Visitor* visitor, Memb er<CachedMatchedProperties>& cachedProperties, WTF::ShouldWeakPointersBeMarkedSt rongly strongify)
40 {
41 // Only honor the cache's weakness semantics if the collection is traced
42 // with WeakPointersActWeak. Otherwise just trace the cachedProperties
43 // strongly, ie. call trace on it.
44 if (cachedProperties && strongify == WTF::WeakPointersActWeak) {
45 // A given cache entry is only kept alive if none of the MatchedProperti es
46 // in the CachedMatchedProperties value contain a dead "properties" fiel d.
47 // If there is a dead field the entire cache entry is removed.
48 HeapVector<MatchedProperties>::iterator it = cachedProperties->matchedPr operties.begin();
49 HeapVector<MatchedProperties>::iterator end = cachedProperties->matchedP roperties.end();
50 for (; it != end; ++it) {
51 if (!visitor->isAlive(it->properties)) {
52 // For now report the cache entry as dead. This might not
53 // be the final result if in a subsequent call for this entry,
54 // the "properties" field has been marked via another path.
55 return true;
56 }
57 }
58 }
59 // At this point none of the entries in the matchedProperties vector
60 // had a dead "properties" field so trace CachedMatchedProperties strongly.
61 visitor->trace(cachedProperties);
62 return false;
63 }
64 #endif
65
66 void CachedMatchedProperties::set(const RenderStyle* style, const RenderStyle* p arentStyle, const MatchResult& matchResult) 38 void CachedMatchedProperties::set(const RenderStyle* style, const RenderStyle* p arentStyle, const MatchResult& matchResult)
67 { 39 {
68 matchedProperties.appendVector(matchResult.matchedProperties); 40 matchedProperties.appendVector(matchResult.matchedProperties);
69 ranges = matchResult.ranges; 41 ranges = matchResult.ranges;
70 42
71 // Note that we don't cache the original RenderStyle instance. It may be fur ther modified. 43 // Note that we don't cache the original RenderStyle instance. It may be fur ther modified.
72 // The RenderStyle in the cache is really just a holder for the substructure s and never used as-is. 44 // The RenderStyle in the cache is really just a holder for the substructure s and never used as-is.
73 this->renderStyle = RenderStyle::clone(style); 45 this->renderStyle = RenderStyle::clone(style);
74 this->parentRenderStyle = RenderStyle::clone(parentStyle); 46 this->parentRenderStyle = RenderStyle::clone(parentStyle);
75 } 47 }
76 48
77 void CachedMatchedProperties::clear() 49 void CachedMatchedProperties::clear()
78 { 50 {
79 matchedProperties.clear(); 51 matchedProperties.clear();
80 renderStyle = nullptr; 52 renderStyle = nullptr;
81 parentRenderStyle = nullptr; 53 parentRenderStyle = nullptr;
82 } 54 }
83 55
84 MatchedPropertiesCache::MatchedPropertiesCache() 56 MatchedPropertiesCache::MatchedPropertiesCache()
85 #if !ENABLE(OILPAN)
86 : m_additionsSinceLastSweep(0) 57 : m_additionsSinceLastSweep(0)
87 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) 58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep)
88 #endif
89 { 59 {
90 } 60 }
91 61
92 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult) 62 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const StyleResolverState& styleResolverState, const MatchResult& matchResult)
93 { 63 {
94 ASSERT(hash); 64 ASSERT(hash);
95 65
96 Cache::iterator it = m_cache.find(hash); 66 Cache::iterator it = m_cache.find(hash);
97 if (it == m_cache.end()) 67 if (it == m_cache.end())
98 return 0; 68 return 0;
99 CachedMatchedProperties* cacheItem = it->value.get(); 69 CachedMatchedProperties* cacheItem = it->value.get();
100 ASSERT(cacheItem); 70 ASSERT(cacheItem);
101 71
102 size_t size = matchResult.matchedProperties.size(); 72 size_t size = matchResult.matchedProperties.size();
103 if (size != cacheItem->matchedProperties.size()) 73 if (size != cacheItem->matchedProperties.size())
104 return 0; 74 return 0;
105 for (size_t i = 0; i < size; ++i) { 75 for (size_t i = 0; i < size; ++i) {
106 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) 76 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i])
107 return 0; 77 return 0;
108 } 78 }
109 if (cacheItem->ranges != matchResult.ranges) 79 if (cacheItem->ranges != matchResult.ranges)
110 return 0; 80 return 0;
111 return cacheItem; 81 return cacheItem;
112 } 82 }
113 83
114 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult) 84 void MatchedPropertiesCache::add(const RenderStyle* style, const RenderStyle* pa rentStyle, unsigned hash, const MatchResult& matchResult)
115 { 85 {
116 #if !ENABLE(OILPAN)
117 static const unsigned maxAdditionsBetweenSweeps = 100; 86 static const unsigned maxAdditionsBetweenSweeps = 100;
118 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps 87 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps
119 && !m_sweepTimer.isActive()) { 88 && !m_sweepTimer.isActive()) {
120 static const unsigned sweepTimeInSeconds = 60; 89 static const unsigned sweepTimeInSeconds = 60;
121 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); 90 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE);
122 } 91 }
123 #endif
124 92
125 ASSERT(hash); 93 ASSERT(hash);
126 Cache::AddResult addResult = m_cache.add(hash, nullptr); 94 Cache::AddResult addResult = m_cache.add(hash, nullptr);
127 if (addResult.isNewEntry) 95 if (addResult.isNewEntry)
128 addResult.storedValue->value = adoptPtr(new CachedMatchedProperties); 96 addResult.storedValue->value = adoptPtr(new CachedMatchedProperties);
129 97
130 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); 98 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get();
131 if (!addResult.isNewEntry) 99 if (!addResult.isNewEntry)
132 cacheItem->clear(); 100 cacheItem->clear();
133 101
134 cacheItem->set(style, parentStyle, matchResult); 102 cacheItem->set(style, parentStyle, matchResult);
135 } 103 }
136 104
137 void MatchedPropertiesCache::clear() 105 void MatchedPropertiesCache::clear()
138 { 106 {
139 m_cache.clear(); 107 m_cache.clear();
140 } 108 }
141 109
142 void MatchedPropertiesCache::clearViewportDependent() 110 void MatchedPropertiesCache::clearViewportDependent()
143 { 111 {
144 Vector<unsigned, 16> toRemove; 112 Vector<unsigned, 16> toRemove;
145 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { 113 for (Cache::iterator it = m_cache.begin(); it != m_cache.end(); ++it) {
146 CachedMatchedProperties* cacheItem = it->value.get(); 114 CachedMatchedProperties* cacheItem = it->value.get();
147 if (cacheItem->renderStyle->hasViewportUnits()) 115 if (cacheItem->renderStyle->hasViewportUnits())
148 toRemove.append(it->key); 116 toRemove.append(it->key);
149 } 117 }
150 m_cache.removeAll(toRemove); 118 m_cache.removeAll(toRemove);
151 } 119 }
152 120
153 #if !ENABLE(OILPAN)
154 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*) 121 void MatchedPropertiesCache::sweep(Timer<MatchedPropertiesCache>*)
155 { 122 {
156 // FIXME(sky): Do we still need this now that we removed PresentationAttribu teStyle? 123 // FIXME(sky): Do we still need this now that we removed PresentationAttribu teStyle?
157 Vector<unsigned, 16> toRemove; 124 Vector<unsigned, 16> toRemove;
158 Cache::iterator it = m_cache.begin(); 125 Cache::iterator it = m_cache.begin();
159 Cache::iterator end = m_cache.end(); 126 Cache::iterator end = m_cache.end();
160 for (; it != end; ++it) { 127 for (; it != end; ++it) {
161 CachedMatchedProperties* cacheItem = it->value.get(); 128 CachedMatchedProperties* cacheItem = it->value.get();
162 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies; 129 Vector<MatchedProperties>& matchedProperties = cacheItem->matchedPropert ies;
163 for (size_t i = 0; i < matchedProperties.size(); ++i) { 130 for (size_t i = 0; i < matchedProperties.size(); ++i) {
164 if (matchedProperties[i].properties->hasOneRef()) { 131 if (matchedProperties[i].properties->hasOneRef()) {
165 toRemove.append(it->key); 132 toRemove.append(it->key);
166 break; 133 break;
167 } 134 }
168 } 135 }
169 } 136 }
170 m_cache.removeAll(toRemove); 137 m_cache.removeAll(toRemove);
171 m_additionsSinceLastSweep = 0; 138 m_additionsSinceLastSweep = 0;
172 } 139 }
173 #endif
174 140
175 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle) 141 bool MatchedPropertiesCache::isCacheable(const Element* element, const RenderSty le* style, const RenderStyle* parentStyle)
176 { 142 {
177 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching. 143 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to docum ent element. We can't skip the applying by caching.
178 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement()) 144 if (element == element->document().documentElement() && element->document(). writingModeSetOnDocumentElement())
179 return false; 145 return false;
180 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e())) 146 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->uniqu e()))
181 return false; 147 return false;
182 if (style->zoom() != RenderStyle::initialZoom()) 148 if (style->zoom() != RenderStyle::initialZoom())
183 return false; 149 return false;
184 if (style->writingMode() != RenderStyle::initialWritingMode()) 150 if (style->writingMode() != RenderStyle::initialWritingMode())
185 return false; 151 return false;
186 if (style->hasCurrentColor()) 152 if (style->hasCurrentColor())
187 return false; 153 return false;
188 // The cache assumes static knowledge about which properties are inherited. 154 // The cache assumes static knowledge about which properties are inherited.
189 if (parentStyle->hasExplicitlyInheritedProperties()) 155 if (parentStyle->hasExplicitlyInheritedProperties())
190 return false; 156 return false;
191 return true; 157 return true;
192 } 158 }
193 159
194 void MatchedPropertiesCache::trace(Visitor* visitor) 160 void MatchedPropertiesCache::trace(Visitor* visitor)
195 { 161 {
196 #if ENABLE(OILPAN)
197 visitor->trace(m_cache);
198 #endif
199 } 162 }
200 163
201 } 164 }
OLDNEW
« no previous file with comments | « sky/engine/core/css/resolver/MatchedPropertiesCache.h ('k') | sky/engine/core/loader/ImageLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698