OLD | NEW |
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 Loading... |
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/style/ComputedStyle.h" | 34 #include "core/style/ComputedStyle.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 void CachedMatchedProperties::set(const ComputedStyle& style, const ComputedStyl
e& parentStyle, const MatchedPropertiesVector& properties) | 38 void CachedMatchedProperties::set(const ComputedStyle& style, const ComputedStyl
e& parentStyle, const MatchResult& matchResult) |
39 { | 39 { |
40 matchedProperties.appendVector(properties); | 40 matchedProperties.appendVector(matchResult.matchedProperties); |
41 | 41 |
42 // Note that we don't cache the original ComputedStyle instance. It may be f
urther modified. | 42 // Note that we don't cache the original ComputedStyle instance. It may be f
urther modified. |
43 // The ComputedStyle in the cache is really just a holder for the substructu
res and never used as-is. | 43 // The ComputedStyle in the cache is really just a holder for the substructu
res and never used as-is. |
44 this->computedStyle = ComputedStyle::clone(style); | 44 this->computedStyle = ComputedStyle::clone(style); |
45 this->parentComputedStyle = ComputedStyle::clone(parentStyle); | 45 this->parentComputedStyle = ComputedStyle::clone(parentStyle); |
46 } | 46 } |
47 | 47 |
48 void CachedMatchedProperties::clear() | 48 void CachedMatchedProperties::clear() |
49 { | 49 { |
50 matchedProperties.clear(); | 50 matchedProperties.clear(); |
51 computedStyle = nullptr; | 51 computedStyle = nullptr; |
52 parentComputedStyle = nullptr; | 52 parentComputedStyle = nullptr; |
53 } | 53 } |
54 | 54 |
55 MatchedPropertiesCache::MatchedPropertiesCache() | 55 MatchedPropertiesCache::MatchedPropertiesCache() |
56 #if !ENABLE(OILPAN) | 56 #if !ENABLE(OILPAN) |
57 : m_additionsSinceLastSweep(0) | 57 : m_additionsSinceLastSweep(0) |
58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) | 58 , m_sweepTimer(this, &MatchedPropertiesCache::sweep) |
59 #endif | 59 #endif |
60 { | 60 { |
61 } | 61 } |
62 | 62 |
63 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const
StyleResolverState& styleResolverState, const MatchedPropertiesVector& properti
es) | 63 const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const
StyleResolverState& styleResolverState, const MatchResult& matchResult) |
64 { | 64 { |
65 ASSERT(hash); | 65 ASSERT(hash); |
66 | 66 |
67 Cache::iterator it = m_cache.find(hash); | 67 Cache::iterator it = m_cache.find(hash); |
68 if (it == m_cache.end()) | 68 if (it == m_cache.end()) |
69 return 0; | 69 return 0; |
70 CachedMatchedProperties* cacheItem = it->value.get(); | 70 CachedMatchedProperties* cacheItem = it->value.get(); |
71 ASSERT(cacheItem); | 71 ASSERT(cacheItem); |
72 | 72 |
73 size_t size = properties.size(); | 73 size_t size = matchResult.matchedProperties.size(); |
74 if (size != cacheItem->matchedProperties.size()) | 74 if (size != cacheItem->matchedProperties.size()) |
75 return 0; | 75 return 0; |
76 if (cacheItem->computedStyle->insideLink() != styleResolverState.style()->in
sideLink()) | 76 if (cacheItem->computedStyle->insideLink() != styleResolverState.style()->in
sideLink()) |
77 return 0; | 77 return 0; |
78 for (size_t i = 0; i < size; ++i) { | 78 for (size_t i = 0; i < size; ++i) { |
79 if (properties[i] != cacheItem->matchedProperties[i]) | 79 if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) |
80 return 0; | 80 return 0; |
81 } | 81 } |
82 return cacheItem; | 82 return cacheItem; |
83 } | 83 } |
84 | 84 |
85 void MatchedPropertiesCache::add(const ComputedStyle& style, const ComputedStyle
& parentStyle, unsigned hash, const MatchedPropertiesVector& properties) | 85 void MatchedPropertiesCache::add(const ComputedStyle& style, const ComputedStyle
& parentStyle, unsigned hash, const MatchResult& matchResult) |
86 { | 86 { |
87 #if !ENABLE(OILPAN) | 87 #if !ENABLE(OILPAN) |
88 static const unsigned maxAdditionsBetweenSweeps = 100; | 88 static const unsigned maxAdditionsBetweenSweeps = 100; |
89 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps | 89 if (++m_additionsSinceLastSweep >= maxAdditionsBetweenSweeps |
90 && !m_sweepTimer.isActive()) { | 90 && !m_sweepTimer.isActive()) { |
91 static const unsigned sweepTimeInSeconds = 60; | 91 static const unsigned sweepTimeInSeconds = 60; |
92 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); | 92 m_sweepTimer.startOneShot(sweepTimeInSeconds, FROM_HERE); |
93 } | 93 } |
94 #endif | 94 #endif |
95 | 95 |
96 ASSERT(hash); | 96 ASSERT(hash); |
97 Cache::AddResult addResult = m_cache.add(hash, nullptr); | 97 Cache::AddResult addResult = m_cache.add(hash, nullptr); |
98 if (addResult.isNewEntry) | 98 if (addResult.isNewEntry) |
99 addResult.storedValue->value = adoptPtrWillBeNoop(new CachedMatchedPrope
rties); | 99 addResult.storedValue->value = adoptPtrWillBeNoop(new CachedMatchedPrope
rties); |
100 | 100 |
101 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); | 101 CachedMatchedProperties* cacheItem = addResult.storedValue->value.get(); |
102 if (!addResult.isNewEntry) | 102 if (!addResult.isNewEntry) |
103 cacheItem->clear(); | 103 cacheItem->clear(); |
104 | 104 |
105 cacheItem->set(style, parentStyle, properties); | 105 cacheItem->set(style, parentStyle, matchResult); |
106 } | 106 } |
107 | 107 |
108 void MatchedPropertiesCache::clear() | 108 void MatchedPropertiesCache::clear() |
109 { | 109 { |
110 m_cache.clear(); | 110 m_cache.clear(); |
111 } | 111 } |
112 | 112 |
113 void MatchedPropertiesCache::clearViewportDependent() | 113 void MatchedPropertiesCache::clearViewportDependent() |
114 { | 114 { |
115 Vector<unsigned, 16> toRemove; | 115 Vector<unsigned, 16> toRemove; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 DEFINE_TRACE(MatchedPropertiesCache) | 162 DEFINE_TRACE(MatchedPropertiesCache) |
163 { | 163 { |
164 #if ENABLE(OILPAN) | 164 #if ENABLE(OILPAN) |
165 visitor->trace(m_cache); | 165 visitor->trace(m_cache); |
166 #endif | 166 #endif |
167 } | 167 } |
168 | 168 |
169 } | 169 } |
OLD | NEW |