OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/discardable_shared_memory_heap.h" | 5 #include "content/common/discardable_shared_memory_heap.h" |
6 | 6 |
7 #include "base/memory/discardable_shared_memory.h" | 7 #include "base/memory/discardable_shared_memory.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 namespace { | 10 namespace { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 void DiscardableSharedMemoryHeap::MergeIntoFreeList(scoped_ptr<Span> span) { | 69 void DiscardableSharedMemoryHeap::MergeIntoFreeList(scoped_ptr<Span> span) { |
70 DCHECK(span->shared_memory_); | 70 DCHECK(span->shared_memory_); |
71 | 71 |
72 // Merge with previous span if possible. | 72 // Merge with previous span if possible. |
73 SpanMap::iterator prev_it = spans_.find(span->start_ - 1); | 73 SpanMap::iterator prev_it = spans_.find(span->start_ - 1); |
74 if (prev_it != spans_.end() && IsInFreeList(prev_it->second)) { | 74 if (prev_it != spans_.end() && IsInFreeList(prev_it->second)) { |
75 scoped_ptr<Span> prev = RemoveFromFreeList(prev_it->second); | 75 scoped_ptr<Span> prev = RemoveFromFreeList(prev_it->second); |
76 DCHECK_EQ(prev->start_ + prev->length_, span->start_); | 76 DCHECK_EQ(prev->start_ + prev->length_, span->start_); |
77 UnregisterSpan(prev.get()); | 77 UnregisterSpan(prev.get()); |
78 spans_.erase(span->start_); | 78 if (span->length_ > 1) |
| 79 spans_.erase(span->start_); |
79 span->start_ -= prev->length_; | 80 span->start_ -= prev->length_; |
80 span->length_ += prev->length_; | 81 span->length_ += prev->length_; |
81 spans_[span->start_] = span.get(); | 82 spans_[span->start_] = span.get(); |
82 } | 83 } |
83 | 84 |
84 // Merge with next span if possible. | 85 // Merge with next span if possible. |
85 SpanMap::iterator next_it = spans_.find(span->start_ + span->length_); | 86 SpanMap::iterator next_it = spans_.find(span->start_ + span->length_); |
86 if (next_it != spans_.end() && IsInFreeList(next_it->second)) { | 87 if (next_it != spans_.end() && IsInFreeList(next_it->second)) { |
87 scoped_ptr<Span> next = RemoveFromFreeList(next_it->second); | 88 scoped_ptr<Span> next = RemoveFromFreeList(next_it->second); |
88 DCHECK_EQ(next->start_, span->start_ + span->length_); | 89 DCHECK_EQ(next->start_, span->start_ + span->length_); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 223 |
223 offset += span->length_; | 224 offset += span->length_; |
224 | 225 |
225 // If |span| is in the free list, remove it. | 226 // If |span| is in the free list, remove it. |
226 if (IsInFreeList(span)) | 227 if (IsInFreeList(span)) |
227 RemoveFromFreeList(span); | 228 RemoveFromFreeList(span); |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 } // namespace content | 232 } // namespace content |
OLD | NEW |