| 16 | {} |
| 17 | |
| 18 | void ScratchArenaManager::trim() |
| 19 | { |
| 20 | for (auto& item : allocs) |
| 21 | { |
| 22 | Alloc& alloc = item.second; |
| 23 | |
| 24 | if (alloc.arenas.empty()) |
| 25 | { |
| 26 | // Free the heap because no more arenas are attached |
| 27 | alloc.heap.reset(); |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | // Decrease the size of the heap if possible |
| 32 | size_t newHeapByteSize = 0; |
| 33 | for (auto arena : alloc.arenas) |
| 34 | newHeapByteSize = max(newHeapByteSize, arena->byteSize); |
| 35 | |
| 36 | if (newHeapByteSize < alloc.heap->getByteSize()) |
| 37 | alloc.heap->realloc(newHeapByteSize); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // Attaches a scratch arena and returns the heap that backs its memory |
| 43 | Heap* ScratchArenaManager::attach(ScratchArena* arena) |
no test coverage detected