OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2014 Samsung Electronics. 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 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 #ifndef CollectionIndexCache_h | 32 #ifndef CollectionIndexCache_h |
33 #define CollectionIndexCache_h | 33 #define CollectionIndexCache_h |
34 | 34 |
35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
36 | 36 |
37 namespace WebCore { | 37 namespace WebCore { |
38 | 38 |
39 template <typename Collection, typename NodeType> | 39 template <typename Collection, typename NodeType> |
40 class CollectionIndexCache { | 40 class CollectionIndexCache { |
41 ALLOW_ONLY_INLINE_ALLOCATION(); | |
41 public: | 42 public: |
42 CollectionIndexCache(); | 43 CollectionIndexCache(); |
43 | 44 |
44 bool isEmpty(const Collection& collection) | 45 bool isEmpty(const Collection& collection) |
45 { | 46 { |
46 if (isCachedNodeCountValid()) | 47 if (isCachedNodeCountValid()) |
47 return !cachedNodeCount(); | 48 return !cachedNodeCount(); |
48 if (cachedNode()) | 49 if (cachedNode()) |
49 return false; | 50 return false; |
50 return !nodeAt(collection, 0); | 51 return !nodeAt(collection, 0); |
51 } | 52 } |
52 bool hasExactlyOneNode(const Collection& collection) | 53 bool hasExactlyOneNode(const Collection& collection) |
53 { | 54 { |
54 if (isCachedNodeCountValid()) | 55 if (isCachedNodeCountValid()) |
55 return cachedNodeCount() == 1; | 56 return cachedNodeCount() == 1; |
56 if (cachedNode()) | 57 if (cachedNode()) |
57 return !cachedNodeIndex() && !nodeAt(collection, 1); | 58 return !cachedNodeIndex() && !nodeAt(collection, 1); |
58 return nodeAt(collection, 0) && !nodeAt(collection, 1); | 59 return nodeAt(collection, 0) && !nodeAt(collection, 1); |
59 } | 60 } |
60 | 61 |
61 unsigned nodeCount(const Collection&); | 62 unsigned nodeCount(const Collection&); |
62 NodeType* nodeAt(const Collection&, unsigned index); | 63 NodeType* nodeAt(const Collection&, unsigned index); |
63 | 64 |
64 void invalidate(); | 65 void invalidate(); |
65 | 66 |
67 void traceAfterDispatch(Visitor* visitor) | |
Mads Ager (chromium)
2014/05/15 10:54:24
This is just a non-virtual trace method, so just c
sof
2014/05/15 22:15:57
Yes, now done + switched to DISALLOW_ALLOCATION()
| |
68 { | |
69 visitor->trace(m_currentNode); | |
70 } | |
71 | |
66 private: | 72 private: |
67 NodeType* nodeBeforeCachedNode(const Collection&, unsigned index); | 73 NodeType* nodeBeforeCachedNode(const Collection&, unsigned index); |
68 NodeType* nodeAfterCachedNode(const Collection&, unsigned index); | 74 NodeType* nodeAfterCachedNode(const Collection&, unsigned index); |
69 | 75 |
70 ALWAYS_INLINE NodeType* cachedNode() const { return m_currentNode; } | 76 ALWAYS_INLINE NodeType* cachedNode() const { return m_currentNode; } |
71 ALWAYS_INLINE unsigned cachedNodeIndex() const { ASSERT(cachedNode()); retur n m_cachedNodeIndex; } | 77 ALWAYS_INLINE unsigned cachedNodeIndex() const { ASSERT(cachedNode()); retur n m_cachedNodeIndex; } |
72 ALWAYS_INLINE void setCachedNode(NodeType* node, unsigned index) | 78 ALWAYS_INLINE void setCachedNode(NodeType* node, unsigned index) |
73 { | 79 { |
74 ASSERT(node); | 80 ASSERT(node); |
75 m_currentNode = node; | 81 m_currentNode = node; |
76 m_cachedNodeIndex = index; | 82 m_cachedNodeIndex = index; |
77 } | 83 } |
78 | 84 |
79 ALWAYS_INLINE bool isCachedNodeCountValid() const { return m_isLengthCacheVa lid; } | 85 ALWAYS_INLINE bool isCachedNodeCountValid() const { return m_isLengthCacheVa lid; } |
80 ALWAYS_INLINE unsigned cachedNodeCount() const { return m_cachedNodeCount; } | 86 ALWAYS_INLINE unsigned cachedNodeCount() const { return m_cachedNodeCount; } |
81 ALWAYS_INLINE void setCachedNodeCount(unsigned length) | 87 ALWAYS_INLINE void setCachedNodeCount(unsigned length) |
82 { | 88 { |
83 m_cachedNodeCount = length; | 89 m_cachedNodeCount = length; |
84 m_isLengthCacheValid = true; | 90 m_isLengthCacheValid = true; |
85 } | 91 } |
86 | 92 |
87 NodeType* m_currentNode; | 93 RawPtrWillBeMember<NodeType> m_currentNode; |
88 unsigned m_cachedNodeCount; | 94 unsigned m_cachedNodeCount; |
89 unsigned m_cachedNodeIndex; | 95 unsigned m_cachedNodeIndex; |
90 unsigned m_isLengthCacheValid : 1; | 96 unsigned m_isLengthCacheValid : 1; |
91 }; | 97 }; |
92 | 98 |
93 template <typename Collection, typename NodeType> | 99 template <typename Collection, typename NodeType> |
94 CollectionIndexCache<Collection, NodeType>::CollectionIndexCache() | 100 CollectionIndexCache<Collection, NodeType>::CollectionIndexCache() |
95 : m_currentNode(0) | 101 : m_currentNode(nullptr) |
96 , m_cachedNodeCount(0) | 102 , m_cachedNodeCount(0) |
97 , m_cachedNodeIndex(0) | 103 , m_cachedNodeIndex(0) |
98 , m_isLengthCacheValid(false) | 104 , m_isLengthCacheValid(false) |
99 { | 105 { |
100 } | 106 } |
101 | 107 |
102 template <typename Collection, typename NodeType> | 108 template <typename Collection, typename NodeType> |
103 void CollectionIndexCache<Collection, NodeType>::invalidate() | 109 void CollectionIndexCache<Collection, NodeType>::invalidate() |
104 { | 110 { |
105 m_currentNode = 0; | 111 m_currentNode = nullptr; |
106 m_isLengthCacheValid = false; | 112 m_isLengthCacheValid = false; |
107 } | 113 } |
108 | 114 |
109 template <typename Collection, typename NodeType> | 115 template <typename Collection, typename NodeType> |
110 inline unsigned CollectionIndexCache<Collection, NodeType>::nodeCount(const Coll ection& collection) | 116 inline unsigned CollectionIndexCache<Collection, NodeType>::nodeCount(const Coll ection& collection) |
111 { | 117 { |
112 if (isCachedNodeCountValid()) | 118 if (isCachedNodeCountValid()) |
113 return cachedNodeCount(); | 119 return cachedNodeCount(); |
114 | 120 |
115 nodeAt(collection, UINT_MAX); | 121 nodeAt(collection, UINT_MAX); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 setCachedNodeCount(currentIndex + 1); | 199 setCachedNodeCount(currentIndex + 1); |
194 return 0; | 200 return 0; |
195 } | 201 } |
196 setCachedNode(currentNode, currentIndex); | 202 setCachedNode(currentNode, currentIndex); |
197 return currentNode; | 203 return currentNode; |
198 } | 204 } |
199 | 205 |
200 } // namespace WebCore | 206 } // namespace WebCore |
201 | 207 |
202 #endif // CollectionIndexCache_h | 208 #endif // CollectionIndexCache_h |
OLD | NEW |