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

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

Issue 656723005: Use C++11 features in core/html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: mike's comments 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
« no previous file with comments | « no previous file | Source/core/html/FormAssociatedElement.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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 nodeAt(collection, UINT_MAX); 120 nodeAt(collection, UINT_MAX);
121 ASSERT(isCachedNodeCountValid()); 121 ASSERT(isCachedNodeCountValid());
122 122
123 return cachedNodeCount(); 123 return cachedNodeCount();
124 } 124 }
125 125
126 template <typename Collection, typename NodeType> 126 template <typename Collection, typename NodeType>
127 inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAt(const Collec tion& collection, unsigned index) 127 inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAt(const Collec tion& collection, unsigned index)
128 { 128 {
129 if (isCachedNodeCountValid() && index >= cachedNodeCount()) 129 if (isCachedNodeCountValid() && index >= cachedNodeCount())
130 return 0; 130 return nullptr;
131 131
132 if (cachedNode()) { 132 if (cachedNode()) {
133 if (index > cachedNodeIndex()) 133 if (index > cachedNodeIndex())
134 return nodeAfterCachedNode(collection, index); 134 return nodeAfterCachedNode(collection, index);
135 if (index < cachedNodeIndex()) 135 if (index < cachedNodeIndex())
136 return nodeBeforeCachedNode(collection, index); 136 return nodeBeforeCachedNode(collection, index);
137 return cachedNode(); 137 return cachedNode();
138 } 138 }
139 139
140 // No valid cache yet, let's find the first matching element. 140 // No valid cache yet, let's find the first matching element.
141 ASSERT(!isCachedNodeCountValid()); 141 ASSERT(!isCachedNodeCountValid());
142 NodeType* firstNode = collection.traverseToFirst(); 142 NodeType* firstNode = collection.traverseToFirst();
143 if (!firstNode) { 143 if (!firstNode) {
144 // The collection is empty. 144 // The collection is empty.
145 setCachedNodeCount(0); 145 setCachedNodeCount(0);
146 return 0; 146 return nullptr;
147 } 147 }
148 setCachedNode(firstNode, 0); 148 setCachedNode(firstNode, 0);
149 return index ? nodeAfterCachedNode(collection, index) : firstNode; 149 return index ? nodeAfterCachedNode(collection, index) : firstNode;
150 } 150 }
151 151
152 template <typename Collection, typename NodeType> 152 template <typename Collection, typename NodeType>
153 inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNod e(const Collection& collection, unsigned index) 153 inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNod e(const Collection& collection, unsigned index)
154 { 154 {
155 ASSERT(cachedNode()); // Cache should be valid. 155 ASSERT(cachedNode()); // Cache should be valid.
156 unsigned currentIndex = cachedNodeIndex(); 156 unsigned currentIndex = cachedNodeIndex();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (index < cachedNodeCount() - 1) 189 if (index < cachedNodeCount() - 1)
190 return nodeBeforeCachedNode(collection, index); 190 return nodeBeforeCachedNode(collection, index);
191 return lastItem; 191 return lastItem;
192 } 192 }
193 193
194 // Forward traversal from the cached node to the requested index. 194 // Forward traversal from the cached node to the requested index.
195 NodeType* currentNode = collection.traverseForwardToOffset(index, *cachedNod e(), currentIndex); 195 NodeType* currentNode = collection.traverseForwardToOffset(index, *cachedNod e(), currentIndex);
196 if (!currentNode) { 196 if (!currentNode) {
197 // Did not find the node. On plus side, we now know the length. 197 // Did not find the node. On plus side, we now know the length.
198 setCachedNodeCount(currentIndex + 1); 198 setCachedNodeCount(currentIndex + 1);
199 return 0; 199 return nullptr;
200 } 200 }
201 setCachedNode(currentNode, currentIndex); 201 setCachedNode(currentNode, currentIndex);
202 return currentNode; 202 return currentNode;
203 } 203 }
204 204
205 } // namespace blink 205 } // namespace blink
206 206
207 #endif // CollectionIndexCache_h 207 #endif // CollectionIndexCache_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/html/FormAssociatedElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698