Chromium Code Reviews| Index: src/zone/zone.cc |
| diff --git a/src/zone/zone.cc b/src/zone/zone.cc |
| index c025af22d84889d11c507d25d68094359256d93b..a8eb41d1a8baf394c863f782782cd9919a7d0fd3 100644 |
| --- a/src/zone/zone.cc |
| +++ b/src/zone/zone.cc |
| @@ -51,7 +51,6 @@ Zone::Zone(AccountingAllocator* allocator) |
| Zone::~Zone() { |
| DeleteAll(); |
| - DeleteKeptSegment(); |
| DCHECK(segment_bytes_allocated_ == 0); |
| } |
| @@ -97,74 +96,26 @@ void Zone::DeleteAll() { |
| static const unsigned char kZapDeadByte = 0xcd; |
| #endif |
| - // Find a segment with a suitable size to keep around. |
| - Segment* keep = nullptr; |
| // Traverse the chained list of segments, zapping (in debug mode) |
| // and freeing every segment except the one we wish to keep. |
|
Michael Starzinger
2016/09/20 10:35:39
nit: Lets drop the "except the one we wish to keep
|
| for (Segment* current = segment_head_; current;) { |
| Segment* next = current->next(); |
| - if (!keep && current->size() <= kMaximumKeptSegmentSize) { |
| - // Unlink the segment we wish to keep from the list. |
| - keep = current; |
| - keep->set_next(nullptr); |
| - } else { |
| - size_t size = current->size(); |
| -#ifdef DEBUG |
| - // Un-poison first so the zapping doesn't trigger ASan complaints. |
| - ASAN_UNPOISON_MEMORY_REGION(current, size); |
| - // Zap the entire current segment (including the header). |
| - memset(current, kZapDeadByte, size); |
| -#endif |
| - segment_bytes_allocated_ -= size; |
| - allocator_->ReturnSegment(current); |
| - } |
| - current = next; |
| - } |
| - |
| - // If we have found a segment we want to keep, we must recompute the |
| - // variables 'position' and 'limit' to prepare for future allocate |
| - // attempts. Otherwise, we must clear the position and limit to |
| - // force a new segment to be allocated on demand. |
| - if (keep) { |
| - Address start = keep->start(); |
| - position_ = RoundUp(start, kAlignment); |
| - limit_ = keep->end(); |
| - // Un-poison so we can re-use the segment later. |
| - ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); |
| -#ifdef DEBUG |
| - // Zap the contents of the kept segment (but not the header). |
| - memset(start, kZapDeadByte, keep->capacity()); |
| -#endif |
| - } else { |
| - position_ = limit_ = 0; |
| - } |
| - |
| - allocation_size_ = 0; |
| - // Update the head segment to be the kept segment (if any). |
| - segment_head_ = keep; |
| -} |
| - |
| -void Zone::DeleteKeptSegment() { |
| -#ifdef DEBUG |
| - // Constant byte value used for zapping dead memory in debug mode. |
| - static const unsigned char kZapDeadByte = 0xcd; |
| -#endif |
| - |
| - DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr); |
| - if (segment_head_ != nullptr) { |
| - size_t size = segment_head_->size(); |
| + size_t size = current->size(); |
| #ifdef DEBUG |
| // Un-poison first so the zapping doesn't trigger ASan complaints. |
| - ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); |
| - // Zap the entire kept segment (including the header). |
| - memset(segment_head_, kZapDeadByte, size); |
| + ASAN_UNPOISON_MEMORY_REGION(current, size); |
| + // Zap the entire current segment (including the header). |
| + memset(current, kZapDeadByte, size); |
| #endif |
| segment_bytes_allocated_ -= size; |
| - allocator_->ReturnSegment(segment_head_); |
| - segment_head_ = nullptr; |
| + allocator_->ReturnSegment(current); |
| + |
| + current = next; |
| } |
| - DCHECK(segment_bytes_allocated_ == 0); |
| + position_ = limit_ = 0; |
| + allocation_size_ = 0; |
| + segment_head_ = nullptr; |
| } |
| // Creates a new segment, sets it size, and pushes it to the front |