@@ -153,23 +153,65 @@ ecma_finalize_lit_storage (void)
153
153
} /* ecma_finalize_lit_storage */
154
154
155
155
/**
156
- * Find or create a literal string.
156
+ * Create a new literal string slot "pool" .
157
157
*
158
- * @return ecma_string_t compressed pointer
158
+ * @return jmem_cpointer_t slot pointer
159
159
*/
160
- ecma_value_t
161
- ecma_find_or_create_literal_string (const lit_utf8_byte_t * chars_p , /**< string to be searched */
162
- lit_utf8_size_t size , /**< size of the string */
163
- bool is_ascii ) /**< encode of the string */
160
+
161
+ jmem_cpointer_t *
162
+ ecma_allocate_new_string_slot (void )
164
163
{
165
- ecma_string_t * string_p =
166
- ( is_ascii ? ecma_new_ecma_string_from_ascii ( chars_p , size ) : ecma_new_ecma_string_from_utf8 ( chars_p , size ));
164
+ ecma_lit_storage_item_t * new_item_p ;
165
+ new_item_p = ( ecma_lit_storage_item_t * ) jmem_pools_alloc ( sizeof ( ecma_lit_storage_item_t ));
167
166
168
- if ( ECMA_IS_DIRECT_STRING ( string_p ) )
167
+ for ( int i = 0 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
169
168
{
170
- return ecma_make_string_value (string_p );
169
+ new_item_p -> values [i ] = JMEM_CP_NULL ;
170
+ }
171
+
172
+ new_item_p -> next_cp = JERRY_CONTEXT (string_list_first_cp );
173
+ JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (string_list_first_cp ), new_item_p );
174
+
175
+ return new_item_p -> values + 0 ;
176
+ } /* ecma_allocate_new_string_slot */
177
+
178
+ /**
179
+ * Find an empty a literal string slot.
180
+ *
181
+ * @return jmem_cpointer_t slot pointer
182
+ */
183
+
184
+ jmem_cpointer_t *
185
+ ecma_find_empty_literal_string_slot (void )
186
+ {
187
+ jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp );
188
+
189
+ while (string_list_cp != JMEM_CP_NULL )
190
+ {
191
+ ecma_lit_storage_item_t * string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t , string_list_cp );
192
+
193
+ for (int i = 0 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
194
+ {
195
+ if (string_list_p -> values [i ] == JMEM_CP_NULL )
196
+ {
197
+ return string_list_p -> values + i ;
198
+ }
199
+ }
200
+ string_list_cp = string_list_p -> next_cp ;
171
201
}
172
202
203
+ return ecma_allocate_new_string_slot ();
204
+ } /* ecma_find_empty_literal_string_slot */
205
+
206
+ /**
207
+ * Find an empty or similar a literal string slot.
208
+ *
209
+ * @return jmem_cpointer_t slot pointer
210
+ */
211
+
212
+ jmem_cpointer_t *
213
+ ecma_find_empty_or_same_literal_string_slot (ecma_string_t * string_p )
214
+ {
173
215
jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp );
174
216
jmem_cpointer_t * empty_cpointer_p = NULL ;
175
217
@@ -189,42 +231,75 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
189
231
else
190
232
{
191
233
ecma_string_t * value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t , string_list_p -> values [i ]);
192
-
193
234
if (ecma_compare_ecma_strings (string_p , value_p ))
194
235
{
195
- /* Return with string if found in the list. */
196
- ecma_deref_ecma_string (string_p );
197
- return ecma_make_string_value (value_p );
236
+ return string_list_p -> values + i ;
198
237
}
199
238
}
200
239
}
201
240
202
241
string_list_cp = string_list_p -> next_cp ;
203
242
}
204
243
205
- ECMA_SET_STRING_AS_STATIC (string_p );
206
- jmem_cpointer_t result ;
207
- JMEM_CP_SET_NON_NULL_POINTER (result , string_p );
208
-
209
244
if (empty_cpointer_p != NULL )
210
245
{
211
- * empty_cpointer_p = result ;
212
- return ecma_make_string_value (string_p );
246
+ return empty_cpointer_p ;
213
247
}
214
248
215
- ecma_lit_storage_item_t * new_item_p ;
216
- new_item_p = ( ecma_lit_storage_item_t * ) jmem_pools_alloc ( sizeof ( ecma_lit_storage_item_t ));
249
+ return ecma_allocate_new_string_slot () ;
250
+ } /* ecma_find_empty_or_same_literal_string_slot */
217
251
218
- new_item_p -> values [0 ] = result ;
219
- for (int i = 1 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
252
+ /**
253
+ * Find or create a literal string.
254
+ *
255
+ * @return ecma_string_t compressed pointer
256
+ */
257
+
258
+ ecma_value_t
259
+ ecma_find_or_create_literal_string (const lit_utf8_byte_t * chars_p , /**< string to be searched */
260
+ lit_utf8_size_t size , /**< size of the string */
261
+ bool is_ascii ) /**< encode of the string */
262
+ {
263
+ ecma_string_t * string_p =
264
+ (is_ascii ? ecma_new_ecma_string_from_ascii (chars_p , size ) : ecma_new_ecma_string_from_utf8 (chars_p , size ));
265
+
266
+ if (ECMA_IS_DIRECT_STRING (string_p ))
220
267
{
221
- new_item_p -> values [ i ] = JMEM_CP_NULL ;
268
+ return ecma_make_string_value ( string_p ) ;
222
269
}
223
270
224
- new_item_p -> next_cp = JERRY_CONTEXT (string_list_first_cp );
225
- JMEM_CP_SET_NON_NULL_POINTER (JERRY_CONTEXT (string_list_first_cp ), new_item_p );
271
+ #if JERRY_LIT_HASHMAP
272
+ const ecma_string_t * hashmap_entry = hashmap_get (& JERRY_CONTEXT (string_hashmap ), string_p );
273
+ if (hashmap_entry != NULL )
274
+ {
275
+ ecma_deref_ecma_string (string_p );
276
+ return ecma_make_string_value (hashmap_entry );
277
+ }
278
+ // Since the string is not found, just find an empty slot
279
+ jmem_cpointer_t * slot = ecma_find_empty_literal_string_slot ();
280
+ #else /* JERRY_LIT_HASHMAP */
281
+ jmem_cpointer_t * slot = ecma_find_empty_or_same_literal_string_slot (string_p );
282
+ if (* slot != JMEM_CP_NULL )
283
+ {
284
+ // The string has been found
285
+ ecma_string_t * value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t , * slot );
286
+ ecma_deref_ecma_string (string_p );
287
+ return ecma_make_string_value (value_p );
288
+ }
289
+ #endif /* JERRY_LIT_HASHMAP */
290
+
291
+ // String has not been found...
292
+ ECMA_SET_STRING_AS_STATIC (string_p );
293
+ jmem_cpointer_t result ;
294
+ JMEM_CP_SET_NON_NULL_POINTER (result , string_p );
295
+ * slot = result ;
296
+
297
+ #if JERRY_LIT_HASHMAP
298
+ hashmap_put (& JERRY_CONTEXT (string_hashmap ), string_p );
299
+ #endif /* JERRY_LIT_HASHMAP */
226
300
227
301
return ecma_make_string_value (string_p );
302
+
228
303
} /* ecma_find_or_create_literal_string */
229
304
230
305
/**
0 commit comments