@@ -153,23 +153,68 @@ ecma_finalize_lit_storage (void)
153153} /* ecma_finalize_lit_storage */
154154
155155/**
156- * Find or create a literal string.
156+ * Create a new literal string slot "pool" .
157157 *
158- * @return ecma_string_t compressed pointer
158+ * @return jmem_cpointer_t slot pointer
159159 */
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+ static jmem_cpointer_t *
162+ ecma_allocate_new_string_slot (void )
164163{
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 ));
167166
168- if ( ECMA_IS_DIRECT_STRING ( string_p ) )
167+ for ( int i = 0 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
169168 {
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+ #if JERRY_LIT_HASHMAP
179+ /**
180+ * Find an empty a literal string slot.
181+ *
182+ * @return jmem_cpointer_t slot pointer
183+ */
184+
185+ static jmem_cpointer_t *
186+ ecma_find_empty_literal_string_slot (void )
187+ {
188+ jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp );
189+
190+ while (string_list_cp != JMEM_CP_NULL )
191+ {
192+ ecma_lit_storage_item_t * string_list_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_lit_storage_item_t , string_list_cp );
193+
194+ for (int i = 0 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
195+ {
196+ if (string_list_p -> values [i ] == JMEM_CP_NULL )
197+ {
198+ return string_list_p -> values + i ;
199+ }
200+ }
201+ string_list_cp = string_list_p -> next_cp ;
171202 }
172203
204+ return ecma_allocate_new_string_slot ();
205+ } /* ecma_find_empty_literal_string_slot */
206+ #endif /* JERRY_LIT_HASHMAP */
207+
208+ /**
209+ * Find an empty or similar a literal string slot.
210+ *
211+ * @return jmem_cpointer_t slot pointer
212+ */
213+
214+ #if !JERRY_LIT_HASHMAP
215+ static jmem_cpointer_t *
216+ ecma_find_empty_or_same_literal_string_slot (ecma_string_t * string_p /**< string to be searched */ )
217+ {
173218 jmem_cpointer_t string_list_cp = JERRY_CONTEXT (string_list_first_cp );
174219 jmem_cpointer_t * empty_cpointer_p = NULL ;
175220
@@ -189,42 +234,76 @@ ecma_find_or_create_literal_string (const lit_utf8_byte_t *chars_p, /**< string
189234 else
190235 {
191236 ecma_string_t * value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t , string_list_p -> values [i ]);
192-
193237 if (ecma_compare_ecma_strings (string_p , value_p ))
194238 {
195- /* Return with string if found in the list. */
196- ecma_deref_ecma_string (string_p );
197- return ecma_make_string_value (value_p );
239+ return string_list_p -> values + i ;
198240 }
199241 }
200242 }
201243
202244 string_list_cp = string_list_p -> next_cp ;
203245 }
204246
205- ECMA_SET_STRING_AS_STATIC (string_p );
206- jmem_cpointer_t result ;
207- JMEM_CP_SET_NON_NULL_POINTER (result , string_p );
208-
209247 if (empty_cpointer_p != NULL )
210248 {
211- * empty_cpointer_p = result ;
212- return ecma_make_string_value (string_p );
249+ return empty_cpointer_p ;
213250 }
214251
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 ));
252+ return ecma_allocate_new_string_slot ();
253+ } /* ecma_find_empty_or_same_literal_string_slot */
254+ #endif /* !JERRY_LIT_HASHMAP */
217255
218- new_item_p -> values [0 ] = result ;
219- for (int i = 1 ; i < ECMA_LIT_STORAGE_VALUE_COUNT ; i ++ )
256+ /**
257+ * Find or create a literal string.
258+ *
259+ * @return ecma_string_t compressed pointer
260+ */
261+
262+ ecma_value_t
263+ ecma_find_or_create_literal_string (const lit_utf8_byte_t * chars_p , /**< string to be searched */
264+ lit_utf8_size_t size , /**< size of the string */
265+ bool is_ascii ) /**< encode of the string */
266+ {
267+ ecma_string_t * string_p =
268+ (is_ascii ? ecma_new_ecma_string_from_ascii (chars_p , size ) : ecma_new_ecma_string_from_utf8 (chars_p , size ));
269+
270+ if (ECMA_IS_DIRECT_STRING (string_p ))
220271 {
221- new_item_p -> values [ i ] = JMEM_CP_NULL ;
272+ return ecma_make_string_value ( string_p ) ;
222273 }
223274
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 );
275+ #if JERRY_LIT_HASHMAP
276+ const ecma_string_t * hashmap_entry = hashmap_get (& JERRY_CONTEXT (string_hashmap ), string_p );
277+ if (hashmap_entry != NULL )
278+ {
279+ ecma_deref_ecma_string (string_p );
280+ return ecma_make_string_value (hashmap_entry );
281+ }
282+ // Since the string is not found, just find an empty slot
283+ jmem_cpointer_t * slot = ecma_find_empty_literal_string_slot ();
284+ #else /* JERRY_LIT_HASHMAP */
285+ jmem_cpointer_t * slot = ecma_find_empty_or_same_literal_string_slot (string_p );
286+ if (* slot != JMEM_CP_NULL )
287+ {
288+ // The string has been found
289+ ecma_string_t * value_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t , * slot );
290+ ecma_deref_ecma_string (string_p );
291+ return ecma_make_string_value (value_p );
292+ }
293+ #endif /* JERRY_LIT_HASHMAP */
294+
295+ // String has not been found...
296+ ECMA_SET_STRING_AS_STATIC (string_p );
297+ jmem_cpointer_t result ;
298+ JMEM_CP_SET_NON_NULL_POINTER (result , string_p );
299+ * slot = result ;
300+
301+ #if JERRY_LIT_HASHMAP
302+ hashmap_put (& JERRY_CONTEXT (string_hashmap ), string_p );
303+ #endif /* JERRY_LIT_HASHMAP */
226304
227305 return ecma_make_string_value (string_p );
306+
228307} /* ecma_find_or_create_literal_string */
229308
230309/**
0 commit comments