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

Side by Side Diff: third_party/WebKit/Source/core/html/CollectionItemsCache.h

Issue 1670463002: [Oilpan] Unify memory usage reporters of Oilpan (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove atomic operations Created 4 years, 10 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 /* 1 /*
2 * Copyright (C) 2012,2013 Google Inc. All rights reserved. 2 * Copyright (C) 2012,2013 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved. 3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 16 matching lines...) Expand all
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef CollectionItemsCache_h 32 #ifndef CollectionItemsCache_h
33 #define CollectionItemsCache_h 33 #define CollectionItemsCache_h
34 34
35 #include "core/html/CollectionIndexCache.h" 35 #include "core/html/CollectionIndexCache.h"
36 #include "wtf/Vector.h" 36 #include "wtf/Vector.h"
37 #include <v8.h> 37 #include <v8.h>
sof 2016/02/16 09:14:38 removeable
peria 2016/02/17 02:31:26 Done.
38 38
39 namespace blink { 39 namespace blink {
40 40
41 template <typename Collection, typename NodeType> 41 template <typename Collection, typename NodeType>
42 class CollectionItemsCache : public CollectionIndexCache<Collection, NodeType> { 42 class CollectionItemsCache : public CollectionIndexCache<Collection, NodeType> {
43 DISALLOW_NEW(); 43 DISALLOW_NEW();
44 44
45 typedef CollectionIndexCache<Collection, NodeType> Base; 45 typedef CollectionIndexCache<Collection, NodeType> Base;
46 46
47 public: 47 public:
48 CollectionItemsCache(); 48 CollectionItemsCache();
49 ~CollectionItemsCache(); 49 ~CollectionItemsCache();
50 50
51 DEFINE_INLINE_VIRTUAL_TRACE() 51 DEFINE_INLINE_VIRTUAL_TRACE()
52 { 52 {
53 visitor->trace(m_cachedList); 53 visitor->trace(m_cachedList);
54 Base::trace(visitor); 54 Base::trace(visitor);
55 } 55 }
56 56
57 unsigned nodeCount(const Collection&); 57 unsigned nodeCount(const Collection&);
58 NodeType* nodeAt(const Collection&, unsigned index); 58 NodeType* nodeAt(const Collection&, unsigned index);
59 void invalidate(); 59 void invalidate();
60 60
61 private: 61 private:
62 ptrdiff_t allocationSize() const { return m_cachedList.capacity() * sizeof(N odeType*); }
63 static void reportExtraMemoryCostForCollectionItemsCache(ptrdiff_t diff)
64 {
65 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff);
66 }
67
68 bool m_listValid; 62 bool m_listValid;
69 WillBeHeapVector<RawPtrWillBeMember<NodeType>> m_cachedList; 63 WillBeHeapVector<RawPtrWillBeMember<NodeType>> m_cachedList;
70 }; 64 };
71 65
72 template <typename Collection, typename NodeType> 66 template <typename Collection, typename NodeType>
73 CollectionItemsCache<Collection, NodeType>::CollectionItemsCache() 67 CollectionItemsCache<Collection, NodeType>::CollectionItemsCache()
74 : m_listValid(false) 68 : m_listValid(false)
75 { 69 {
76 } 70 }
77 71
78 template <typename Collection, typename NodeType> 72 template <typename Collection, typename NodeType>
79 CollectionItemsCache<Collection, NodeType>::~CollectionItemsCache() 73 CollectionItemsCache<Collection, NodeType>::~CollectionItemsCache()
80 { 74 {
81 if (ptrdiff_t diff = allocationSize())
82 reportExtraMemoryCostForCollectionItemsCache(-diff);
83 } 75 }
84 76
85 template <typename Collection, typename NodeType> 77 template <typename Collection, typename NodeType>
86 void CollectionItemsCache<Collection, NodeType>::invalidate() 78 void CollectionItemsCache<Collection, NodeType>::invalidate()
87 { 79 {
88 Base::invalidate(); 80 Base::invalidate();
89 if (m_listValid) { 81 if (m_listValid) {
90 m_cachedList.shrink(0); 82 m_cachedList.shrink(0);
91 m_listValid = false; 83 m_listValid = false;
92 } 84 }
93 } 85 }
94 86
95 template <class Collection, class NodeType> 87 template <class Collection, class NodeType>
96 unsigned CollectionItemsCache<Collection, NodeType>::nodeCount(const Collection& collection) 88 unsigned CollectionItemsCache<Collection, NodeType>::nodeCount(const Collection& collection)
97 { 89 {
98 if (this->isCachedNodeCountValid()) 90 if (this->isCachedNodeCountValid())
99 return this->cachedNodeCount(); 91 return this->cachedNodeCount();
100 92
101 NodeType* currentNode = collection.traverseToFirst(); 93 NodeType* currentNode = collection.traverseToFirst();
102 unsigned currentIndex = 0; 94 unsigned currentIndex = 0;
103 ptrdiff_t oldCapacity = allocationSize();
104 while (currentNode) { 95 while (currentNode) {
105 m_cachedList.append(currentNode); 96 m_cachedList.append(currentNode);
106 currentNode = collection.traverseForwardToOffset(currentIndex + 1, *curr entNode, currentIndex); 97 currentNode = collection.traverseForwardToOffset(currentIndex + 1, *curr entNode, currentIndex);
107 } 98 }
108 if (ptrdiff_t diff = allocationSize() - oldCapacity)
109 reportExtraMemoryCostForCollectionItemsCache(diff);
110 99
111 this->setCachedNodeCount(m_cachedList.size()); 100 this->setCachedNodeCount(m_cachedList.size());
112 m_listValid = true; 101 m_listValid = true;
113 return this->cachedNodeCount(); 102 return this->cachedNodeCount();
114 } 103 }
115 104
116 template <typename Collection, typename NodeType> 105 template <typename Collection, typename NodeType>
117 inline NodeType* CollectionItemsCache<Collection, NodeType>::nodeAt(const Collec tion& collection, unsigned index) 106 inline NodeType* CollectionItemsCache<Collection, NodeType>::nodeAt(const Collec tion& collection, unsigned index)
118 { 107 {
119 if (m_listValid) { 108 if (m_listValid) {
120 ASSERT(this->isCachedNodeCountValid()); 109 ASSERT(this->isCachedNodeCountValid());
121 return index < this->cachedNodeCount() ? m_cachedList[index] : nullptr; 110 return index < this->cachedNodeCount() ? m_cachedList[index] : nullptr;
122 } 111 }
123 return Base::nodeAt(collection, index); 112 return Base::nodeAt(collection, index);
124 } 113 }
125 114
126 } // namespace blink 115 } // namespace blink
127 116
128 #endif // CollectionItemsCache_h 117 #endif // CollectionItemsCache_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698