| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/dom/NthIndexCache.h" | 6 #include "core/dom/NthIndexCache.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 ParentMap::AddResult addResult = m_parentMap->add(&parent, nullptr); | 30 ParentMap::AddResult addResult = m_parentMap->add(&parent, nullptr); |
| 31 if (addResult.isNewEntry) | 31 if (addResult.isNewEntry) |
| 32 addResult.storedValue->value = adoptPtrWillBeNoop(new NthIndexData()); | 32 addResult.storedValue->value = adoptPtrWillBeNoop(new NthIndexData()); |
| 33 | 33 |
| 34 ASSERT(addResult.storedValue->value); | 34 ASSERT(addResult.storedValue->value); |
| 35 return *addResult.storedValue->value; | 35 return *addResult.storedValue->value; |
| 36 } | 36 } |
| 37 | 37 |
| 38 unsigned NthIndexCache::NthIndexData::cacheNthIndices(Element& element) | 38 unsigned NthIndexCache::NthIndexData::cacheNthIndices(Element& element) |
| 39 { | 39 { |
| 40 ASSERT(!element.isPseudoElement()); |
| 40 unsigned index = 0; | 41 unsigned index = 0; |
| 41 // The frequency at which we cache the nth-index for a set of siblings. | 42 // The frequency at which we cache the nth-index for a set of siblings. |
| 42 // A spread value of 3 means every third Element will have its nth-index cac
hed. | 43 // A spread value of 3 means every third Element will have its nth-index cac
hed. |
| 43 // Using a spread value > 1 is done to save memory. Looking up the nth-index
will | 44 // Using a spread value > 1 is done to save memory. Looking up the nth-index
will |
| 44 // still be done in constant time in terms of sibling count, at most 'spread
' | 45 // still be done in constant time in terms of sibling count, at most 'spread
' |
| 45 // elements will be traversed. | 46 // elements will be traversed. |
| 46 const unsigned spread = 3; | 47 const unsigned spread = 3; |
| 47 unsigned count = 0; | 48 unsigned count = 0; |
| 48 for (Element* sibling = ElementTraversal::firstChild(*element.parentNode());
sibling; sibling = ElementTraversal::nextSibling(*sibling)) { | 49 for (Element* sibling = ElementTraversal::firstChild(*element.parentNode());
sibling; sibling = ElementTraversal::nextSibling(*sibling)) { |
| 49 if (!(++count % spread)) | 50 if (!(++count % spread)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 #endif | 64 #endif |
| 64 } | 65 } |
| 65 | 66 |
| 66 #if !ENABLE(OILPAN) | 67 #if !ENABLE(OILPAN) |
| 67 NthIndexCache::NthIndexData::~NthIndexData() | 68 NthIndexCache::NthIndexData::~NthIndexData() |
| 68 { | 69 { |
| 69 } | 70 } |
| 70 #endif | 71 #endif |
| 71 | 72 |
| 72 } // namespace blink | 73 } // namespace blink |
| OLD | NEW |