void WeakSet::sweep() { for (WeakBlock* block = m_blocks.head(); block; block = block->next()) block->sweep(); resetAllocator(); }
WeakBlock::FreeCell* WeakSet::addAllocator() { WeakBlock* block = WeakBlock::create(); m_heap->didAllocate(WeakBlock::blockSize); m_blocks.append(block); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); ASSERT(!sweepResult.isNull() && sweepResult.freeList); return sweepResult.freeList; }
WeakSet::~WeakSet() { WeakBlock* next = 0; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); WeakBlock::destroy(block); } m_blocks.clear(); }
WeakSet::~WeakSet() { WeakBlock* next = 0; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); heap()->blockAllocator().deallocate(WeakBlock::destroy(block)); } m_blocks.clear(); }
WeakBlock::FreeCell* WeakSet::addAllocator() { if (!isOnList()) heap()->objectSpace().addActiveWeakSet(this); WeakBlock* block = WeakBlock::create(*heap(), m_container); heap()->didAllocate(WeakBlock::blockSize); m_blocks.append(block); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); ASSERT(!sweepResult.isNull() && sweepResult.freeList); return sweepResult.freeList; }
WeakBlock::FreeCell* WeakSet::tryFindAllocator() { while (m_nextAllocator) { WeakBlock* block = m_nextAllocator; m_nextAllocator = m_nextAllocator->next(); WeakBlock::SweepResult sweepResult = block->takeSweepResult(); if (sweepResult.freeList) return sweepResult.freeList; } return 0; }
WeakSet::~WeakSet() { if (isOnList()) remove(); Heap& heap = *this->heap(); WeakBlock* next = 0; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); WeakBlock::destroy(heap, block); } m_blocks.clear(); }
void WeakSet::sweep() { WeakBlock* next; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); // If a block is completely empty, a new sweep won't have any effect. if (block->isEmpty()) continue; block->takeSweepResult(); // Force a new sweep by discarding the last sweep. block->sweep(); } }
void WeakSet::shrink() { WeakBlock* next; for (WeakBlock* block = m_blocks.head(); block; block = next) { next = block->next(); if (block->isEmpty()) removeAllocator(block); } resetAllocator(); if (m_blocks.isEmpty() && isOnList()) remove(); }
void WeakSet::sweep() { for (WeakBlock* block = m_blocks.head(); block;) { heap()->sweepNextLogicallyEmptyWeakBlock(); WeakBlock* nextBlock = block->next(); block->sweep(); if (block->isLogicallyEmptyButNotFree()) { // If this WeakBlock is logically empty, but still has Weaks pointing into it, // we can't destroy it just yet. Detach it from the WeakSet and hand ownership // to the Heap so we don't pin down the entire MarkedBlock or LargeAllocation. m_blocks.remove(block); heap()->addLogicallyEmptyWeakBlock(block); block->disconnectContainer(); } block = nextBlock; } resetAllocator(); }
void WeakBlock::spreadHit() { //Destroy adjacent weakblocks if applicable if(linked) { Sector* sector = Sector::current(); if (!sector) { log_debug << "no current sector" << std::endl; return; } for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) { WeakBlock* wb = dynamic_cast<WeakBlock*>(i->get()); if (!wb) continue; if (wb == this) continue; if (wb->state != STATE_NORMAL) continue; float dx = fabsf(wb->get_pos().x - bbox.p1.x); float dy = fabsf(wb->get_pos().y - bbox.p1.y); if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning(); } } }
bool Heap::sweepNextLogicallyEmptyWeakBlock() { if (m_indexOfNextLogicallyEmptyWeakBlockToSweep == WTF::notFound) return false; WeakBlock* block = m_logicallyEmptyWeakBlocks[m_indexOfNextLogicallyEmptyWeakBlockToSweep]; block->sweep(); if (block->isEmpty()) { std::swap(m_logicallyEmptyWeakBlocks[m_indexOfNextLogicallyEmptyWeakBlockToSweep], m_logicallyEmptyWeakBlocks.last()); m_logicallyEmptyWeakBlocks.removeLast(); WeakBlock::destroy(block); } else m_indexOfNextLogicallyEmptyWeakBlockToSweep++; if (m_indexOfNextLogicallyEmptyWeakBlockToSweep >= m_logicallyEmptyWeakBlocks.size()) { m_indexOfNextLogicallyEmptyWeakBlockToSweep = WTF::notFound; return false; } return true; }