Merges h1 and h2 when Chunk(h1)->next is h2 and Chunk(h2)->prev is c1. We merge Chunk(h2) into Chunk(h1).
| 570 | // Merges h1 and h2 when Chunk(h1)->next is h2 and Chunk(h2)->prev is c1. |
| 571 | // We merge Chunk(h2) into Chunk(h1). |
| 572 | void BFCAllocator::Merge(BFCAllocator::ChunkHandle h1, |
| 573 | BFCAllocator::ChunkHandle h2) { |
| 574 | Chunk* c1 = ChunkFromHandle(h1); |
| 575 | Chunk* c2 = ChunkFromHandle(h2); |
| 576 | // We can only merge chunks that are not in use. |
| 577 | CHECK(!c1->in_use() && !c2->in_use()); |
| 578 | |
| 579 | // c1's prev doesn't change, still points to the same ptr, and is |
| 580 | // still not in use. |
| 581 | |
| 582 | // Fix up neighbor pointers |
| 583 | // |
| 584 | // c1 <-> c2 <-> c3 should become |
| 585 | // c1 <-> c3 |
| 586 | |
| 587 | BFCAllocator::ChunkHandle h3 = c2->next; |
| 588 | c1->next = h3; |
| 589 | CHECK(c2->prev == h1); |
| 590 | if (h3 != kInvalidChunkHandle) { |
| 591 | BFCAllocator::Chunk* c3 = ChunkFromHandle(h3); |
| 592 | c3->prev = h1; |
| 593 | } |
| 594 | |
| 595 | // Set the new size |
| 596 | c1->size += c2->size; |
| 597 | |
| 598 | // Pick latest free time. |
| 599 | c1->freed_at_count = std::max(c1->freed_at_count, c2->freed_at_count); |
| 600 | |
| 601 | DeleteChunk(h2); |
| 602 | } |
| 603 | |
| 604 | void BFCAllocator::DeleteChunk(ChunkHandle h) { |
| 605 | // Delete h and cleanup all state |
no test coverage detected