mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:02:45 +00:00 
			
		
		
		
	 41a072bded
			
		
	
	
		41a072bded
		
	
	
	
	
		
			
			This patch introduces the "environment coordinate" concept, which
encodes the distance from a variable access to the binding it ends up
resolving to.
EnvironmentCoordinate has two fields:
    - hops:  The number of hops up the lexical environment chain we have
             to make before getting to the resolved binding.
    - index: The index of the resolved binding within its declarative
             environment record.
Whenever a variable lookup resolves somewhere inside a declarative
environment, we now cache the coordinates and reuse them in subsequent
lookups. This is achieved via a coordinate cache in JS::Identifier.
Note that non-strict direct eval() breaks this optimization and so it
will not be performed if the resolved environment has been permanently
screwed by eval().
This makes variable access *significantly* faster. :^)
		
	
			
		
			
				
	
	
		
			18 lines
		
	
	
	
		
			254 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
	
		
			254 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibJS/Forward.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| struct EnvironmentCoordinate {
 | |
|     size_t hops { 0 };
 | |
|     size_t index { 0 };
 | |
| };
 | |
| 
 | |
| }
 |