void WeakMapData::DeadKeyCleaner::finalizeUnconditionally() { if (m_liveKeyCount > m_target->m_map.size() / 2) { RELEASE_ASSERT(m_liveKeyCount <= m_target->m_map.size()); int deadCount = m_target->m_map.size() - m_liveKeyCount; if (!deadCount) return; Vector<JSObject*> deadEntries; deadEntries.reserveCapacity(deadCount); for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) { if (Heap::isMarked(it->key)) continue; deadEntries.uncheckedAppend(it->key); } for (size_t i = 0; i < deadEntries.size(); i++) m_target->m_map.remove(deadEntries[i]); } else { MapType newMap; for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) { if (!Heap::isMarked(it->key)) continue; newMap.add(it->key, it->value); } m_target->m_map.swap(newMap); } }
int main(int argc, const char * argv[]) { std::set<std::unique_ptr<DynamicDomain>> domainSet; domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(7, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(1, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(2, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(6, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(3, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(4, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(9001, &domainSet))); domainSet.insert(std::unique_ptr<DynamicDomain>(new DynamicDomain(5, &domainSet))); MapType intervalMap; std::set<std::unique_ptr<DynamicDomain>>::iterator it = domainSet.begin(); intervalMap.add(std::make_pair(MapType::interval_type::closed_interval(it->get(), std::next(it, 1)->get()), 1)); intervalMap.add(std::make_pair(MapType::interval_type::closed_interval(std::next(it, 2)->get(), std::next(it, 3)->get()), 1)); intervalMap.add(std::make_pair(MapType::interval_type::closed_interval(std::next(it, 1)->get(), std::next(it, 3)->get()), 1)); for (auto element : intervalMap) { std::cout << "Domain: [" << element.first.lower()->intValue << ", " << element.first.upper()->intValue << "] = " << element.second << std::endl; } }