Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
| 8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
| 9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
| 10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 break; | 620 break; |
| 621 default: | 621 default: |
| 622 stats.other.addResource(resource); | 622 stats.other.addResource(resource); |
| 623 break; | 623 break; |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 return stats; | 627 return stats; |
| 628 } | 628 } |
| 629 | 629 |
| 630 void MemoryCache::evictResources() { | 630 void MemoryCache::evictResources(EvictResourcePolicy policy) { |
| 631 while (true) { | 631 for (auto resourceMapIter = m_resourceMaps.begin(); |
| 632 ResourceMapIndex::iterator resourceMapIter = m_resourceMaps.begin(); | 632 resourceMapIter != m_resourceMaps.end();) { |
| 633 if (resourceMapIter == m_resourceMaps.end()) | |
| 634 break; | |
| 635 ResourceMap* resources = resourceMapIter->value.get(); | 633 ResourceMap* resources = resourceMapIter->value.get(); |
| 636 while (true) { | 634 HeapVector<Member<MemoryCacheEntry>> unusedPreloads; |
| 637 ResourceMap::iterator resourceIter = resources->begin(); | 635 for (auto resourceIter = resources->begin(); |
| 638 if (resourceIter == resources->end()) | 636 resourceIter != resources->end();) { |
| 639 break; | 637 DCHECK(resourceIter.get()); |
| 640 evict(resourceIter->value.get()); | 638 DCHECK(resourceIter->value.get()); |
| 639 DCHECK(resourceIter->value->resource()); | |
| 640 if (policy == EvictAllResources || | |
| 641 !(resourceIter->value->resource() && | |
| 642 resourceIter->value->resource()->isUnusedPreload())) { | |
| 643 evict(resourceIter->value.get()); | |
| 644 } else { | |
| 645 // Store unused preloads aside, so they could be added back later. | |
| 646 // That is in order to avoid the performance impact of iterating over | |
| 647 // the same resource multiple times. | |
| 648 unusedPreloads.append(resourceIter->value.get()); | |
| 649 resources->remove(resourceIter); | |
| 650 } | |
| 651 resourceIter = resources->begin(); | |
|
Charlie Harrison
2016/10/10 21:00:21
Optional: Can this update step go into the for loo
| |
| 641 } | 652 } |
| 642 m_resourceMaps.remove(resourceMapIter); | 653 for (const auto& unusedPreload : unusedPreloads) { |
| 654 KURL url = | |
| 655 removeFragmentIdentifierIfNeeded(unusedPreload->resource()->url()); | |
| 656 resources->set(url, unusedPreload); | |
| 657 } | |
| 658 // We may iterate multiple times over resourceMaps with unused preloads. | |
| 659 // That's extremely unlikely to have any real-life performance impact. | |
| 660 if (!resources->size()) { | |
| 661 m_resourceMaps.remove(resourceMapIter); | |
| 662 resourceMapIter = m_resourceMaps.begin(); | |
| 663 } else { | |
| 664 ++resourceMapIter; | |
| 665 } | |
| 643 } | 666 } |
| 644 } | 667 } |
| 645 | 668 |
| 646 void MemoryCache::prune() { | 669 void MemoryCache::prune() { |
| 647 TRACE_EVENT0("renderer", "MemoryCache::prune()"); | 670 TRACE_EVENT0("renderer", "MemoryCache::prune()"); |
| 648 | 671 |
| 649 if (m_inPruneResources) | 672 if (m_inPruneResources) |
| 650 return; | 673 return; |
| 651 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && | 674 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && |
| 652 m_deadSize <= m_maxDeadCapacity) // Fast path. | 675 m_deadSize <= m_maxDeadCapacity) // Fast path. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) { | 776 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) { |
| 754 MemoryCacheEntry* ex = getEntryForResource(x); | 777 MemoryCacheEntry* ex = getEntryForResource(x); |
| 755 MemoryCacheEntry* ey = getEntryForResource(y); | 778 MemoryCacheEntry* ey = getEntryForResource(y); |
| 756 DCHECK(ex); | 779 DCHECK(ex); |
| 757 DCHECK(ey); | 780 DCHECK(ey); |
| 758 return lruListFor(ex->m_accessCount, x->size()) == | 781 return lruListFor(ex->m_accessCount, x->size()) == |
| 759 lruListFor(ey->m_accessCount, y->size()); | 782 lruListFor(ey->m_accessCount, y->size()); |
| 760 } | 783 } |
| 761 | 784 |
| 762 } // namespace blink | 785 } // namespace blink |
| OLD | NEW |