| OLD | NEW |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 template <class Collection, class NodeType> | 80 template <class Collection, class NodeType> |
| 81 unsigned CollectionItemsCache<Collection, NodeType>::nodeCount( | 81 unsigned CollectionItemsCache<Collection, NodeType>::nodeCount( |
| 82 const Collection& collection) { | 82 const Collection& collection) { |
| 83 if (this->isCachedNodeCountValid()) | 83 if (this->isCachedNodeCountValid()) |
| 84 return this->cachedNodeCount(); | 84 return this->cachedNodeCount(); |
| 85 | 85 |
| 86 NodeType* currentNode = collection.traverseToFirst(); | 86 NodeType* currentNode = collection.traverseToFirst(); |
| 87 unsigned currentIndex = 0; | 87 unsigned currentIndex = 0; |
| 88 while (currentNode) { | 88 while (currentNode) { |
| 89 m_cachedList.append(currentNode); | 89 m_cachedList.push_back(currentNode); |
| 90 currentNode = collection.traverseForwardToOffset( | 90 currentNode = collection.traverseForwardToOffset( |
| 91 currentIndex + 1, *currentNode, currentIndex); | 91 currentIndex + 1, *currentNode, currentIndex); |
| 92 } | 92 } |
| 93 | 93 |
| 94 this->setCachedNodeCount(m_cachedList.size()); | 94 this->setCachedNodeCount(m_cachedList.size()); |
| 95 m_listValid = true; | 95 m_listValid = true; |
| 96 return this->cachedNodeCount(); | 96 return this->cachedNodeCount(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 template <typename Collection, typename NodeType> | 99 template <typename Collection, typename NodeType> |
| 100 inline NodeType* CollectionItemsCache<Collection, NodeType>::nodeAt( | 100 inline NodeType* CollectionItemsCache<Collection, NodeType>::nodeAt( |
| 101 const Collection& collection, | 101 const Collection& collection, |
| 102 unsigned index) { | 102 unsigned index) { |
| 103 if (m_listValid) { | 103 if (m_listValid) { |
| 104 DCHECK(this->isCachedNodeCountValid()); | 104 DCHECK(this->isCachedNodeCountValid()); |
| 105 return index < this->cachedNodeCount() ? m_cachedList[index] : nullptr; | 105 return index < this->cachedNodeCount() ? m_cachedList[index] : nullptr; |
| 106 } | 106 } |
| 107 return Base::nodeAt(collection, index); | 107 return Base::nodeAt(collection, index); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace blink | 110 } // namespace blink |
| 111 | 111 |
| 112 #endif // CollectionItemsCache_h | 112 #endif // CollectionItemsCache_h |
| OLD | NEW |