@@ -384,11 +384,11 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
384384
385385 if (str1_size == 0 )
386386 {
387- return ecma_copy_or_ref_ecma_string (string2_p );
387+ return ecma_ref_ecma_string (string2_p );
388388 }
389389 else if (str2_size == 0 )
390390 {
391- return ecma_copy_or_ref_ecma_string (string1_p );
391+ return ecma_ref_ecma_string (string1_p );
392392 }
393393
394394 const lit_utf8_size_t new_size = str1_size + str2_size ;
@@ -442,111 +442,30 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
442442 return string_desc_p ;
443443} /* ecma_concat_ecma_strings */
444444
445- /**
446- * Copy ecma-string
447- *
448- * @return pointer to copy of ecma-string with reference counter set to 1
449- */
450- static ecma_string_t *
451- ecma_copy_ecma_string (ecma_string_t * string_desc_p ) /**< string descriptor */
452- {
453- JERRY_ASSERT (string_desc_p != NULL );
454- JERRY_ASSERT (string_desc_p -> refs_and_container >= ECMA_STRING_REF_ONE );
455-
456- ecma_string_t * new_str_p ;
457-
458- switch (ECMA_STRING_GET_CONTAINER (string_desc_p ))
459- {
460- case ECMA_STRING_CONTAINER_LIT_TABLE :
461- case ECMA_STRING_CONTAINER_UINT32_IN_DESC :
462- case ECMA_STRING_CONTAINER_MAGIC_STRING :
463- case ECMA_STRING_CONTAINER_MAGIC_STRING_EX :
464- {
465- new_str_p = ecma_alloc_string ();
466-
467- * new_str_p = * string_desc_p ;
468-
469- new_str_p -> refs_and_container = ECMA_STRING_SET_REF_TO_ONE (new_str_p -> refs_and_container );
470-
471- break ;
472- }
473-
474- case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING :
475- {
476- new_str_p = ecma_alloc_string ();
477- * new_str_p = * string_desc_p ;
478- new_str_p -> refs_and_container = ECMA_STRING_SET_REF_TO_ONE (new_str_p -> refs_and_container );
479-
480- const ecma_string_heap_header_t * data_p = ECMA_GET_NON_NULL_POINTER (ecma_string_heap_header_t ,
481- string_desc_p -> u .utf8_collection_cp );
482- JERRY_ASSERT (data_p != NULL );
483- const size_t data_size = data_p -> size + sizeof (ecma_string_heap_header_t );
484- ecma_string_heap_header_t * new_data_p = (ecma_string_heap_header_t * ) jmem_heap_alloc_block (data_size );
485- memcpy (new_data_p , data_p , data_size );
486-
487- ECMA_SET_NON_NULL_POINTER (new_str_p -> u .utf8_collection_cp , new_data_p );
488-
489- break ;
490- }
491-
492- case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING :
493- {
494- new_str_p = ecma_alloc_string ();
495- * new_str_p = * string_desc_p ;
496- new_str_p -> refs_and_container = ECMA_STRING_SET_REF_TO_ONE (new_str_p -> refs_and_container );
497-
498- const lit_utf8_byte_t * data_p = ECMA_GET_NON_NULL_POINTER (lit_utf8_byte_t ,
499- string_desc_p -> u .ascii_string .ascii_collection_cp );
500-
501- JERRY_ASSERT (data_p != NULL );
502- const size_t data_size = string_desc_p -> u .ascii_string .size ;
503- lit_utf8_byte_t * new_data_p = (lit_utf8_byte_t * ) jmem_heap_alloc_block (data_size );
504- memcpy (new_data_p , data_p , data_size );
505-
506- ECMA_SET_NON_NULL_POINTER (new_str_p -> u .ascii_string .ascii_collection_cp , new_data_p );
507-
508- break ;
509- }
510-
511- default :
512- {
513- JERRY_UNREACHABLE ();
514- }
515- }
516-
517- JERRY_ASSERT (ecma_compare_ecma_strings (string_desc_p , new_str_p ));
518-
519- return new_str_p ;
520- } /* ecma_copy_ecma_string */
521-
522445/**
523446 * Increase reference counter of ecma-string.
524447 *
525448 * @return pointer to same ecma-string descriptor with increased reference counter
526449 * or the ecma-string's copy with reference counter set to 1
527450 */
528451ecma_string_t *
529- ecma_copy_or_ref_ecma_string (ecma_string_t * string_p ) /**< string descriptor */
452+ ecma_ref_ecma_string (ecma_string_t * string_p ) /**< string descriptor */
530453{
531454 JERRY_ASSERT (string_p != NULL );
532455 JERRY_ASSERT (string_p -> refs_and_container >= ECMA_STRING_REF_ONE );
533456
534- if (unlikely (string_p -> refs_and_container >= ECMA_STRING_MAX_REF ))
457+ if (likely (string_p -> refs_and_container < ECMA_STRING_MAX_REF ))
535458 {
536- /* First trying to free unreachable objects that maybe refer to the string */
537- ecma_gc_run ();
538-
539- if (string_p -> refs_and_container >= ECMA_STRING_MAX_REF )
540- {
541- /* reference counter was not changed during GC, copying string */
542- return ecma_copy_ecma_string (string_p );
543- }
459+ /* Increase reference counter. */
460+ string_p -> refs_and_container = (uint16_t ) (string_p -> refs_and_container + ECMA_STRING_REF_ONE );
461+ }
462+ else
463+ {
464+ jerry_fatal (ERR_REF_COUNT_LIMIT );
544465 }
545466
546- /* Increase reference counter. */
547- string_p -> refs_and_container = (uint16_t ) (string_p -> refs_and_container + ECMA_STRING_REF_ONE );
548467 return string_p ;
549- } /* ecma_copy_or_ref_ecma_string */
468+ } /* ecma_ref_ecma_string */
550469
551470/**
552471 * Decrease reference counter and deallocate ecma-string
0 commit comments