28
28
29
29
#if ENABLED (JERRY_LCACHE )
30
30
31
+ /**
32
+ * Bitshift index for calculating hash.
33
+ */
34
+ #if ENABLED (JERRY_CPOINTER_32_BIT )
35
+ #define ECMA_LCACHE_HASH_BITSHIFT_INDEX (2 * JMEM_ALIGNMENT_LOG)
36
+ #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
37
+ #define ECMA_LCACHE_HASH_BITSHIFT_INDEX 0
38
+ #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
39
+
31
40
/**
32
41
* Mask for hash bits
33
42
*/
34
- #define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)
43
+ #define ECMA_LCACHE_HASH_MASK (( ECMA_LCACHE_HASH_ROWS_COUNT - 1) << ECMA_LCACHE_HASH_BITSHIFT_INDEX )
35
44
36
45
/**
37
46
* Bitshift index for creating property identifier
@@ -69,15 +78,15 @@ ecma_lcache_row_index (jmem_cpointer_t object_cp, /**< compressed pointer to obj
69
78
{
70
79
/* Randomize the property name with the object pointer using a xor operation,
71
80
* so properties of different objects with the same name can be cached effectively. */
72
- return (size_t ) ((name_cp ^ object_cp ) & ECMA_LCACHE_HASH_MASK );
81
+ return (size_t ) ((( name_cp ^ object_cp ) & ECMA_LCACHE_HASH_MASK ) >> ECMA_LCACHE_HASH_BITSHIFT_INDEX );
73
82
} /* ecma_lcache_row_index */
74
83
75
84
/**
76
85
* Insert an entry into LCache
77
86
*/
78
87
void
79
- ecma_lcache_insert (ecma_object_t * object_p , /**< object */
80
- jmem_cpointer_t name_cp , /**< property name */
88
+ ecma_lcache_insert (const ecma_object_t * object_p , /**< object */
89
+ const jmem_cpointer_t name_cp , /**< property name */
81
90
ecma_property_t * prop_p ) /**< property */
82
91
{
83
92
JERRY_ASSERT (object_p != NULL );
@@ -91,31 +100,32 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
91
100
ECMA_SET_NON_NULL_POINTER (object_cp , object_p );
92
101
93
102
size_t row_index = ecma_lcache_row_index (object_cp , name_cp );
94
- ecma_lcache_hash_entry_t * entries_p = JERRY_CONTEXT (lcache ) [row_index ];
103
+ ecma_lcache_hash_entry_t * entry_p = JERRY_CONTEXT (lcache ) [row_index ];
104
+ ecma_lcache_hash_entry_t * entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH ;
95
105
96
- uint32_t entry_index ;
97
- for (entry_index = 0 ; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH ; entry_index ++ )
106
+ do
98
107
{
99
- if (entries_p [ entry_index ]. id == 0 )
108
+ if (entry_p -> id == 0 )
100
109
{
101
- break ;
110
+ goto insert ;
102
111
}
112
+
113
+ entry_p ++ ;
103
114
}
115
+ while (entry_p < entry_end_p );
104
116
105
- if (entry_index == ECMA_LCACHE_HASH_ROW_LENGTH )
106
- {
107
- /* Invalidate the last entry. */
108
- ecma_lcache_invalidate_entry (entries_p + ECMA_LCACHE_HASH_ROW_LENGTH - 1 );
117
+ /* Invalidate the last entry. */
118
+ ecma_lcache_invalidate_entry (-- entry_p );
109
119
110
- /* Shift other entries towards the end. */
111
- for (uint32_t i = ECMA_LCACHE_HASH_ROW_LENGTH - 1 ; i > 0 ; i -- )
112
- {
113
- entries_p [ i ] = entries_p [ i - 1 ] ;
114
- }
115
- entry_index = 0 ;
120
+ /* Shift other entries towards the end. */
121
+ for (uint32_t i = 0 ; i < ECMA_LCACHE_HASH_ROW_LENGTH - 1 ; i ++ )
122
+ {
123
+ entry_p -> id = entry_p [ -1 ]. id ;
124
+ entry_p -> prop_p = entry_p [ -1 ]. prop_p ;
125
+ entry_p -- ;
116
126
}
117
127
118
- ecma_lcache_hash_entry_t * entry_p = entries_p + entry_index ;
128
+ insert :
119
129
entry_p -> prop_p = prop_p ;
120
130
entry_p -> id = ECMA_LCACHE_CREATE_ID (object_cp , name_cp );
121
131
@@ -129,7 +139,7 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
129
139
* NULL otherwise
130
140
*/
131
141
inline ecma_property_t * JERRY_ATTR_ALWAYS_INLINE
132
- ecma_lcache_lookup (ecma_object_t * object_p , /**< object */
142
+ ecma_lcache_lookup (const ecma_object_t * object_p , /**< object */
133
143
const ecma_string_t * prop_name_p ) /**< property's name */
134
144
{
135
145
JERRY_ASSERT (object_p != NULL );
@@ -138,36 +148,35 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
138
148
jmem_cpointer_t object_cp ;
139
149
ECMA_SET_NON_NULL_POINTER (object_cp , object_p );
140
150
141
- ecma_property_t prop_name_type ;
151
+ ecma_property_t prop_name_type = ECMA_DIRECT_STRING_PTR ;
142
152
jmem_cpointer_t prop_name_cp ;
143
153
144
- if (ECMA_IS_DIRECT_STRING (prop_name_p ))
154
+ if (JERRY_UNLIKELY ( ECMA_IS_DIRECT_STRING (prop_name_p ) ))
145
155
{
146
156
prop_name_type = (ecma_property_t ) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p );
147
157
prop_name_cp = (jmem_cpointer_t ) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p );
148
158
}
149
159
else
150
160
{
151
- prop_name_type = ECMA_DIRECT_STRING_PTR ;
152
161
ECMA_SET_NON_NULL_POINTER (prop_name_cp , prop_name_p );
153
162
}
154
163
155
164
size_t row_index = ecma_lcache_row_index (object_cp , prop_name_cp );
156
165
157
166
ecma_lcache_hash_entry_t * entry_p = JERRY_CONTEXT (lcache ) [row_index ];
158
167
ecma_lcache_hash_entry_t * entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH ;
159
-
160
168
ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp , prop_name_cp );
161
169
162
- while ( entry_p < entry_end_p )
170
+ do
163
171
{
164
- if (entry_p -> id == id && ECMA_PROPERTY_GET_NAME_TYPE (* entry_p -> prop_p ) == prop_name_type )
172
+ if (entry_p -> id == id && JERRY_LIKELY ( ECMA_PROPERTY_GET_NAME_TYPE (* entry_p -> prop_p ) == prop_name_type ) )
165
173
{
166
174
JERRY_ASSERT (entry_p -> prop_p != NULL && ecma_is_property_lcached (entry_p -> prop_p ));
167
175
return entry_p -> prop_p ;
168
176
}
169
177
entry_p ++ ;
170
178
}
179
+ while (entry_p < entry_end_p );
171
180
172
181
return NULL ;
173
182
} /* ecma_lcache_lookup */
@@ -176,8 +185,8 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
176
185
* Invalidate LCache entries associated with given object and property name / property
177
186
*/
178
187
void
179
- ecma_lcache_invalidate (ecma_object_t * object_p , /**< object */
180
- jmem_cpointer_t name_cp , /**< property name */
188
+ ecma_lcache_invalidate (const ecma_object_t * object_p , /**< object */
189
+ const jmem_cpointer_t name_cp , /**< property name */
181
190
ecma_property_t * prop_p ) /**< property */
182
191
{
183
192
JERRY_ASSERT (object_p != NULL );
0 commit comments