33
33
*/
34
34
#define ECMA_LCACHE_HASH_MASK (ECMA_LCACHE_HASH_ROWS_COUNT - 1)
35
35
36
+ /**
37
+ * Bitshift index for creating property identifier
38
+ */
39
+ #define ECMA_LCACHE_HASH_ENTRY_ID_SHIFT (8 * sizeof (jmem_cpointer_t))
40
+
41
+ /**
42
+ * Create property identifier
43
+ */
44
+ #define ECMA_LCACHE_CREATE_ID (object_cp , name_cp ) \
45
+ (((ecma_lcache_hash_entry_id_t) (object_cp) << ECMA_LCACHE_HASH_ENTRY_ID_SHIFT) | (name_cp))
46
+
36
47
/**
37
48
* Invalidate specified LCache entry
38
49
*/
39
50
static inline void JERRY_ATTR_ALWAYS_INLINE
40
51
ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t * entry_p ) /**< entry to invalidate */
41
52
{
42
53
JERRY_ASSERT (entry_p != NULL );
43
- JERRY_ASSERT (entry_p -> object_cp != ECMA_NULL_POINTER );
54
+ JERRY_ASSERT (entry_p -> id != 0 );
44
55
JERRY_ASSERT (entry_p -> prop_p != NULL );
45
56
46
- entry_p -> object_cp = ECMA_NULL_POINTER ;
57
+ entry_p -> id = 0 ;
47
58
ecma_set_property_lcached (entry_p -> prop_p , false);
48
59
} /* ecma_lcache_invalidate_entry */
49
60
@@ -54,11 +65,11 @@ ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to i
54
65
*/
55
66
static inline size_t JERRY_ATTR_ALWAYS_INLINE
56
67
ecma_lcache_row_index (jmem_cpointer_t object_cp , /**< compressed pointer to object */
57
- lit_string_hash_t name_hash ) /**< property name hash */
68
+ jmem_cpointer_t name_cp ) /**< compressed pointer to property name */
58
69
{
59
- /* Randomize the hash of the property name with the object pointer using a xor operation,
70
+ /* Randomize the property name with the object pointer using a xor operation,
60
71
* so properties of different objects with the same name can be cached effectively. */
61
- return (size_t ) ((name_hash ^ object_cp ) & ECMA_LCACHE_HASH_MASK );
72
+ return (size_t ) ((name_cp ^ object_cp ) & ECMA_LCACHE_HASH_MASK );
62
73
} /* ecma_lcache_row_index */
63
74
64
75
/**
@@ -79,14 +90,13 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
79
90
80
91
ECMA_SET_NON_NULL_POINTER (object_cp , object_p );
81
92
82
- lit_string_hash_t name_hash = ecma_string_get_property_name_hash (* prop_p , name_cp );
83
- size_t row_index = ecma_lcache_row_index (object_cp , name_hash );
93
+ size_t row_index = ecma_lcache_row_index (object_cp , name_cp );
84
94
ecma_lcache_hash_entry_t * entries_p = JERRY_CONTEXT (lcache ) [row_index ];
85
95
86
96
uint32_t entry_index ;
87
97
for (entry_index = 0 ; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH ; entry_index ++ )
88
98
{
89
- if (entries_p [entry_index ].object_cp == ECMA_NULL_POINTER )
99
+ if (entries_p [entry_index ].id == 0 )
90
100
{
91
101
break ;
92
102
}
@@ -102,14 +112,12 @@ ecma_lcache_insert (ecma_object_t *object_p, /**< object */
102
112
{
103
113
entries_p [i ] = entries_p [i - 1 ];
104
114
}
105
-
106
115
entry_index = 0 ;
107
116
}
108
117
109
118
ecma_lcache_hash_entry_t * entry_p = entries_p + entry_index ;
110
- ECMA_SET_NON_NULL_POINTER (entry_p -> object_cp , object_p );
111
- entry_p -> prop_name_cp = name_cp ;
112
119
entry_p -> prop_p = prop_p ;
120
+ entry_p -> id = ECMA_LCACHE_CREATE_ID (object_cp , name_cp );
113
121
114
122
ecma_set_property_lcached (entry_p -> prop_p , true);
115
123
} /* ecma_lcache_insert */
@@ -132,53 +140,32 @@ ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
132
140
133
141
ecma_property_t prop_name_type ;
134
142
jmem_cpointer_t prop_name_cp ;
135
- lit_string_hash_t name_hash ;
136
143
137
144
if (ECMA_IS_DIRECT_STRING (prop_name_p ))
138
145
{
139
146
prop_name_type = (ecma_property_t ) ECMA_GET_DIRECT_STRING_TYPE (prop_name_p );
140
-
141
- uintptr_t value = ECMA_GET_DIRECT_STRING_VALUE (prop_name_p );
142
- prop_name_cp = (jmem_cpointer_t ) value ;
143
- name_hash = (lit_string_hash_t ) value ;
144
-
145
- if (prop_name_type == ECMA_DIRECT_STRING_MAGIC_EX )
146
- {
147
- name_hash = (lit_string_hash_t ) (name_hash + LIT_MAGIC_STRING__COUNT );
148
- }
147
+ prop_name_cp = (jmem_cpointer_t ) ECMA_GET_DIRECT_STRING_VALUE (prop_name_p );
149
148
}
150
149
else
151
150
{
152
151
prop_name_type = ECMA_DIRECT_STRING_PTR ;
153
-
154
152
ECMA_SET_NON_NULL_POINTER (prop_name_cp , prop_name_p );
155
- name_hash = prop_name_p -> hash ;
156
153
}
157
154
158
- size_t row_index = ecma_lcache_row_index (object_cp , name_hash );
155
+ size_t row_index = ecma_lcache_row_index (object_cp , prop_name_cp );
159
156
160
157
ecma_lcache_hash_entry_t * entry_p = JERRY_CONTEXT (lcache ) [row_index ];
161
158
ecma_lcache_hash_entry_t * entry_end_p = entry_p + ECMA_LCACHE_HASH_ROW_LENGTH ;
162
159
160
+ ecma_lcache_hash_entry_id_t id = ECMA_LCACHE_CREATE_ID (object_cp , prop_name_cp );
161
+
163
162
while (entry_p < entry_end_p )
164
163
{
165
- if (entry_p -> object_cp == object_cp
166
- && entry_p -> prop_name_cp == prop_name_cp )
164
+ if (entry_p -> id == id && ECMA_PROPERTY_GET_NAME_TYPE (* entry_p -> prop_p ) == prop_name_type )
167
165
{
168
- ecma_property_t * prop_p = entry_p -> prop_p ;
169
-
170
- JERRY_ASSERT (prop_p != NULL && ecma_is_property_lcached (prop_p ));
171
-
172
- if (ECMA_PROPERTY_GET_NAME_TYPE (* prop_p ) == prop_name_type )
173
- {
174
- return prop_p ;
175
- }
176
- }
177
- else
178
- {
179
- /* They can be equal, but generic string comparison is too costly. */
166
+ JERRY_ASSERT (entry_p -> prop_p != NULL && ecma_is_property_lcached (entry_p -> prop_p ));
167
+ return entry_p -> prop_p ;
180
168
}
181
-
182
169
entry_p ++ ;
183
170
}
184
171
@@ -202,18 +189,17 @@ ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
202
189
jmem_cpointer_t object_cp ;
203
190
ECMA_SET_NON_NULL_POINTER (object_cp , object_p );
204
191
205
- lit_string_hash_t name_hash = ecma_string_get_property_name_hash (* prop_p , name_cp );
206
- size_t row_index = ecma_lcache_row_index (object_cp , name_hash );
192
+ size_t row_index = ecma_lcache_row_index (object_cp , name_cp );
207
193
ecma_lcache_hash_entry_t * entry_p = JERRY_CONTEXT (lcache ) [row_index ];
208
194
209
195
while (true)
210
196
{
211
197
/* The property must be present. */
212
198
JERRY_ASSERT (entry_p - JERRY_CONTEXT (lcache ) [row_index ] < ECMA_LCACHE_HASH_ROW_LENGTH );
213
199
214
- if (entry_p -> object_cp != ECMA_NULL_POINTER && entry_p -> prop_p == prop_p )
200
+ if (entry_p -> id != 0 && entry_p -> prop_p == prop_p )
215
201
{
216
- JERRY_ASSERT (entry_p -> object_cp == object_cp );
202
+ JERRY_ASSERT (entry_p -> id == ECMA_LCACHE_CREATE_ID ( object_cp , name_cp ) );
217
203
218
204
ecma_lcache_invalidate_entry (entry_p );
219
205
return ;
0 commit comments