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

Side by Side Diff: Source/core/html/CollectionIndexCache.h

Issue 152903002: Move m_overridesItemAfter member from LiveNodeListBase to HTMLCollection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: No change Created 6 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
« no previous file with comments | « Source/core/dom/LiveNodeList.h ('k') | Source/core/html/HTMLCollection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 template <typename Collection> 123 template <typename Collection>
124 inline Node* CollectionIndexCache<Collection>::nodeAt(const Collection& collecti on, unsigned index) 124 inline Node* CollectionIndexCache<Collection>::nodeAt(const Collection& collecti on, unsigned index)
125 { 125 {
126 if (cachedNode() && cachedNodeIndex() == index) 126 if (cachedNode() && cachedNodeIndex() == index)
127 return cachedNode(); 127 return cachedNode();
128 128
129 if (isCachedNodeCountValid() && cachedNodeCount() <= index) 129 if (isCachedNodeCountValid() && cachedNodeCount() <= index)
130 return 0; 130 return 0;
131 131
132 ContainerNode& root = collection.rootNode(); 132 ContainerNode& root = collection.rootNode();
133 if (isCachedNodeCountValid() && !collection.overridesItemAfter() && isLastNo deCloserThanLastOrCachedNode(index)) { 133 if (isCachedNodeCountValid() && collection.canTraverseBackward() && isLastNo deCloserThanLastOrCachedNode(index)) {
134 Node* lastNode = collection.itemBefore(0); 134 Node* lastNode = collection.itemBefore(0);
135 ASSERT(lastNode); 135 ASSERT(lastNode);
136 setCachedNode(lastNode, cachedNodeCount() - 1); 136 setCachedNode(lastNode, cachedNodeCount() - 1);
137 } else if (!cachedNode() || isFirstNodeCloserThanCachedNode(index) || (colle ction.overridesItemAfter() && index < cachedNodeIndex())) { 137 } else if (!cachedNode() || isFirstNodeCloserThanCachedNode(index) || (!coll ection.canTraverseBackward() && index < cachedNodeIndex())) {
138 Node* firstNode = collection.traverseToFirstElement(root); 138 Node* firstNode = collection.traverseToFirstElement(root);
139 if (!firstNode) { 139 if (!firstNode) {
140 setCachedNodeCount(0); 140 setCachedNodeCount(0);
141 return 0; 141 return 0;
142 } 142 }
143 setCachedNode(firstNode, 0); 143 setCachedNode(firstNode, 0);
144 ASSERT(!cachedNodeIndex()); 144 ASSERT(!cachedNodeIndex());
145 } 145 }
146 146
147 if (cachedNodeIndex() == index) 147 if (cachedNodeIndex() == index)
148 return cachedNode(); 148 return cachedNode();
149 149
150 return nodeBeforeOrAfterCachedNode(collection, index, root); 150 return nodeBeforeOrAfterCachedNode(collection, index, root);
151 } 151 }
152 152
153 template <typename Collection> 153 template <typename Collection>
154 inline Node* CollectionIndexCache<Collection>::nodeBeforeOrAfterCachedNode(const Collection& collection, unsigned index, const ContainerNode &root) 154 inline Node* CollectionIndexCache<Collection>::nodeBeforeOrAfterCachedNode(const Collection& collection, unsigned index, const ContainerNode &root)
155 { 155 {
156 unsigned currentIndex = cachedNodeIndex(); 156 unsigned currentIndex = cachedNodeIndex();
157 Node* currentNode = cachedNode(); 157 Node* currentNode = cachedNode();
158 ASSERT(currentNode); 158 ASSERT(currentNode);
159 ASSERT(currentIndex != index); 159 ASSERT(currentIndex != index);
160 160
161 if (index < cachedNodeIndex()) { 161 if (index < cachedNodeIndex()) {
162 ASSERT(!collection.overridesItemAfter()); 162 ASSERT(collection.canTraverseBackward());
163 while ((currentNode = collection.itemBefore(currentNode))) { 163 while ((currentNode = collection.itemBefore(currentNode))) {
164 ASSERT(currentIndex); 164 ASSERT(currentIndex);
165 currentIndex--; 165 currentIndex--;
166 if (currentIndex == index) { 166 if (currentIndex == index) {
167 setCachedNode(currentNode, currentIndex); 167 setCachedNode(currentNode, currentIndex);
168 return currentNode; 168 return currentNode;
169 } 169 }
170 } 170 }
171 ASSERT_NOT_REACHED(); 171 ASSERT_NOT_REACHED();
172 return 0; 172 return 0;
(...skipping 26 matching lines...) Expand all
199 if (cachedNodeIndex() < index) 199 if (cachedNodeIndex() < index)
200 return false; 200 return false;
201 201
202 unsigned distanceFromCachedNode = cachedNodeIndex() - index; 202 unsigned distanceFromCachedNode = cachedNodeIndex() - index;
203 return index < distanceFromCachedNode; 203 return index < distanceFromCachedNode;
204 } 204 }
205 205
206 } // namespace WebCore 206 } // namespace WebCore
207 207
208 #endif // CollectionIndexCache_h 208 #endif // CollectionIndexCache_h
OLDNEW
« no previous file with comments | « Source/core/dom/LiveNodeList.h ('k') | Source/core/html/HTMLCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698