mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:32:44 +00:00 
			
		
		
		
	 83bd675477
			
		
	
	
		83bd675477
		
	
	
	
	
		
			
			Instead of iterating *all* swept cells when pruning weak containers, only iterate the cells actually *in* the container. Also, instead of compiling a list of all swept cells, we can simply check the Cell::state() flag to know if something should be pruned.
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			913 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			913 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Runtime/WeakMap.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| WeakMap* WeakMap::create(GlobalObject& global_object)
 | |
| {
 | |
|     return global_object.heap().allocate<WeakMap>(global_object, *global_object.weak_map_prototype());
 | |
| }
 | |
| 
 | |
| WeakMap::WeakMap(Object& prototype)
 | |
|     : Object(prototype)
 | |
|     , WeakContainer(heap())
 | |
| {
 | |
| }
 | |
| 
 | |
| WeakMap::~WeakMap()
 | |
| {
 | |
| }
 | |
| 
 | |
| void WeakMap::remove_dead_cells(Badge<Heap>)
 | |
| {
 | |
|     // FIXME: Do this in a single pass.
 | |
|     Vector<Cell*> to_remove;
 | |
|     for (auto& it : m_values) {
 | |
|         if (it.key->state() != Cell::State::Live)
 | |
|             to_remove.append(it.key);
 | |
|     }
 | |
|     for (auto* cell : to_remove)
 | |
|         m_values.remove(cell);
 | |
| }
 | |
| 
 | |
| void WeakMap::visit_edges(Visitor& visitor)
 | |
| {
 | |
|     Base::visit_edges(visitor);
 | |
|     for (auto& entry : m_values)
 | |
|         visitor.visit(entry.value);
 | |
| }
 | |
| 
 | |
| }
 |