mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:12:43 +00:00 
			
		
		
		
	 4699c81fc1
			
		
	
	
		4699c81fc1
		
	
	
	
	
		
			
			This patch makes IteratorRecord an Object. Although it's not exposed to
author code, this does allow us to store it in a VM register.
Now that we can store it in a VM register, we don't need to convert it
back and forth between IteratorRecord and Object when accessing it from
bytecode.
The big win here is avoiding 3 [[Get]] accesses on every iteration step
of for..of loops. There are also a bunch of smaller efficiencies gained.
20% speed-up on this microbenchmark:
    function go(a) {
        for (const p of a) {
        }
    }
    const a = [];
    a.length = 1_000_000;
    go(a);
		
	
			
		
			
				
	
	
		
			36 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, David Tuin <davidot@serenityos.org>
 | |
|  * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibJS/Runtime/Iterator.h>
 | |
| #include <LibJS/Runtime/Object.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| // 27.1.4.3 Properties of Async-from-Sync Iterator Instances, https://tc39.es/ecma262/#sec-properties-of-async-from-sync-iterator-instances
 | |
| class AsyncFromSyncIterator final : public Object {
 | |
|     JS_OBJECT(AsyncFromSyncIterator, Object);
 | |
|     JS_DECLARE_ALLOCATOR(AsyncFromSyncIterator);
 | |
| 
 | |
| public:
 | |
|     static NonnullGCPtr<AsyncFromSyncIterator> create(Realm&, NonnullGCPtr<IteratorRecord> sync_iterator_record);
 | |
| 
 | |
|     virtual ~AsyncFromSyncIterator() override = default;
 | |
| 
 | |
|     void visit_edges(Visitor& visitor) override;
 | |
| 
 | |
|     IteratorRecord& sync_iterator_record() { return m_sync_iterator_record; }
 | |
|     IteratorRecord const& sync_iterator_record() const { return m_sync_iterator_record; }
 | |
| 
 | |
| private:
 | |
|     AsyncFromSyncIterator(Realm&, NonnullGCPtr<IteratorRecord> sync_iterator_record);
 | |
| 
 | |
|     NonnullGCPtr<IteratorRecord> m_sync_iterator_record; // [[SyncIteratorRecord]]
 | |
| };
 | |
| 
 | |
| }
 |