@@ -627,53 +627,44 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
627
627
jerry_fatal (ERR_OUT_OF_MEMORY);
628
628
}
629
629
630
- ecma_string_t * string_desc_p = ecma_alloc_string ();
631
- string_desc_p->refs = 1 ;
632
- string_desc_p->is_stack_var = false ;
633
- string_desc_p->container = ECMA_STRING_CONTAINER_CONCATENATION;
634
-
635
- string_desc_p->u .common_field = 0 ;
636
-
637
- string1_p = ecma_copy_or_ref_ecma_string (string1_p);
638
- string2_p = ecma_copy_or_ref_ecma_string (string2_p);
639
-
640
- ECMA_SET_NON_NULL_POINTER (string_desc_p->u .concatenation .string1_cp , string1_p);
641
- ECMA_SET_NON_NULL_POINTER (string_desc_p->u .concatenation .string2_cp , string2_p);
642
-
643
630
ecma_char_t str1_last_code_unit = ecma_string_get_char_at_pos (string1_p, ecma_string_get_length (string1_p) - 1 );
644
631
ecma_char_t str2_first_code_unit = ecma_string_get_char_at_pos (string2_p, 0 );
645
632
646
- string_desc_p-> u . concatenation . is_surrogate_pair_sliced = (lit_is_code_unit_high_surrogate (str1_last_code_unit)
647
- && lit_is_code_unit_low_surrogate (str2_first_code_unit));
633
+ bool is_surrogate_pair_sliced = (lit_is_code_unit_high_surrogate (str1_last_code_unit)
634
+ && lit_is_code_unit_low_surrogate (str2_first_code_unit));
648
635
649
- if (!string_desc_p->u .concatenation .is_surrogate_pair_sliced )
650
- {
651
- lit_utf8_size_t buffer_size = ecma_string_get_size (string2_p);
636
+ lit_utf8_size_t buffer_size = str1_size + str2_size - (lit_utf8_size_t ) (is_surrogate_pair_sliced ?
637
+ LIT_UTF8_CESU8_SURROGATE_SIZE_DIF : 0 );
652
638
653
- MEM_DEFINE_LOCAL_ARRAY (utf8_str_p, buffer_size, lit_utf8_byte_t );
639
+ lit_utf8_byte_t *str_p = ( lit_utf8_byte_t *) mem_heap_alloc_block ( buffer_size, MEM_HEAP_ALLOC_SHORT_TERM );
654
640
655
- ssize_t sz = ecma_string_to_utf8_string (string2_p, utf8_str_p, (ssize_t ) buffer_size);
656
- JERRY_ASSERT (sz > 0 );
641
+ ssize_t bytes_copied1, bytes_copied2;
657
642
658
- string_desc_p->hash = lit_utf8_string_hash_combine (string1_p->hash , utf8_str_p, buffer_size);
643
+ bytes_copied1 = ecma_string_to_utf8_string (string1_p, str_p, (ssize_t ) str1_size);
644
+ JERRY_ASSERT (bytes_copied1 > 0 );
659
645
660
- MEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
646
+ if (!is_surrogate_pair_sliced)
647
+ {
648
+ bytes_copied2 = ecma_string_to_utf8_string (string2_p, str_p + str1_size, (ssize_t ) str2_size);
649
+ JERRY_ASSERT (bytes_copied2 > 0 );
661
650
}
662
651
else
663
652
{
664
- lit_utf8_size_t buffer_size = ecma_string_get_size (string_desc_p);
665
-
666
- MEM_DEFINE_LOCAL_ARRAY (utf8_str_p, buffer_size, lit_utf8_byte_t );
653
+ bytes_copied2 = ecma_string_to_utf8_string (string2_p,
654
+ str_p + str1_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT + 1 ,
655
+ (ssize_t ) buffer_size - bytes_copied1
656
+ + LIT_UTF8_MAX_BYTES_IN_CODE_UNIT);
657
+ JERRY_ASSERT (bytes_copied2 > 0 );
667
658
668
- ssize_t sz = ecma_string_to_utf8_string (string_desc_p, utf8_str_p, (ssize_t ) buffer_size);
669
- JERRY_ASSERT (sz > 0 );
670
-
671
- string_desc_p->hash = lit_utf8_string_calc_hash (utf8_str_p, buffer_size);
672
-
673
- MEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
659
+ lit_code_point_t surrogate_code_point = lit_convert_surrogate_pair_to_code_point (str1_last_code_unit,
660
+ str2_first_code_unit);
661
+ lit_code_point_to_utf8 (surrogate_code_point, str_p + str1_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT);
674
662
}
663
+ ecma_string_t *str_concat_p = ecma_new_ecma_string_from_utf8 (str_p, buffer_size);
675
664
676
- return string_desc_p;
665
+ mem_heap_free_block ((void *) str_p);
666
+
667
+ return str_concat_p;
677
668
} /* ecma_concat_ecma_strings */
678
669
679
670
/* *
@@ -706,16 +697,6 @@ ecma_copy_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
706
697
break ;
707
698
}
708
699
709
- case ECMA_STRING_CONTAINER_CONCATENATION:
710
- {
711
- ecma_string_t *part1_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_desc_p->u .concatenation .string1_cp );
712
- ecma_string_t *part2_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_desc_p->u .concatenation .string2_cp );
713
-
714
- new_str_p = ecma_concat_ecma_strings (part1_p, part2_p);
715
-
716
- break ;
717
- }
718
-
719
700
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
720
701
{
721
702
ecma_number_t *num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t , string_desc_p->u .number_cp );
@@ -840,20 +821,6 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
840
821
841
822
break ;
842
823
}
843
- case ECMA_STRING_CONTAINER_CONCATENATION:
844
- {
845
- ecma_string_t *string1_p, *string2_p;
846
-
847
- string1_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
848
- string_p->u .concatenation .string1_cp );
849
- string2_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
850
- string_p->u .concatenation .string2_cp );
851
-
852
- ecma_deref_ecma_string (string1_p);
853
- ecma_deref_ecma_string (string2_p);
854
-
855
- break ;
856
- }
857
824
case ECMA_STRING_CONTAINER_LIT_TABLE:
858
825
case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
859
826
case ECMA_STRING_CONTAINER_MAGIC_STRING:
@@ -924,7 +891,6 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
924
891
925
892
case ECMA_STRING_CONTAINER_LIT_TABLE:
926
893
case ECMA_STRING_CONTAINER_HEAP_CHUNKS:
927
- case ECMA_STRING_CONTAINER_CONCATENATION:
928
894
case ECMA_STRING_CONTAINER_MAGIC_STRING:
929
895
case ECMA_STRING_CONTAINER_MAGIC_STRING_EX:
930
896
{
@@ -1052,54 +1018,7 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
1052
1018
1053
1019
break ;
1054
1020
}
1055
- case ECMA_STRING_CONTAINER_CONCATENATION:
1056
- {
1057
- const ecma_string_t *string1_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
1058
- string_desc_p->u .concatenation .string1_cp );
1059
- const ecma_string_t *string2_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t ,
1060
- string_desc_p->u .concatenation .string2_cp );
1061
-
1062
- lit_utf8_byte_t *dest_p = buffer_p;
1063
-
1064
- ssize_t bytes_copied1, bytes_copied2;
1065
-
1066
- bytes_copied1 = ecma_string_to_utf8_string (string1_p, dest_p, buffer_size);
1067
- JERRY_ASSERT (bytes_copied1 > 0 );
1068
-
1069
- dest_p += ecma_string_get_size (string1_p);
1070
1021
1071
- if (!string_desc_p->u .concatenation .is_surrogate_pair_sliced )
1072
- {
1073
- bytes_copied2 = ecma_string_to_utf8_string (string2_p, dest_p, buffer_size - bytes_copied1);
1074
- JERRY_ASSERT (bytes_copied2 > 0 );
1075
- }
1076
- else
1077
- {
1078
- dest_p -= LIT_UTF8_MAX_BYTES_IN_CODE_UNIT;
1079
-
1080
- ecma_char_t high_surrogate = lit_utf8_string_code_unit_at (dest_p, LIT_UTF8_MAX_BYTES_IN_CODE_UNIT, 0 );
1081
- JERRY_ASSERT (lit_is_code_unit_high_surrogate (high_surrogate));
1082
-
1083
- bytes_copied2 = ecma_string_to_utf8_string (string2_p,
1084
- dest_p + 1 ,
1085
- buffer_size - bytes_copied1 + LIT_UTF8_MAX_BYTES_IN_CODE_UNIT);
1086
- JERRY_ASSERT (bytes_copied2 > 0 );
1087
-
1088
- ecma_char_t low_surrogate = lit_utf8_string_code_unit_at (dest_p + 1 , LIT_UTF8_MAX_BYTES_IN_CODE_UNIT, 0 );
1089
- JERRY_ASSERT (lit_is_code_unit_low_surrogate (low_surrogate));
1090
-
1091
- lit_code_point_t surrogate_code_point = lit_convert_surrogate_pair_to_code_point (high_surrogate,
1092
- low_surrogate);
1093
- lit_code_point_to_utf8 (surrogate_code_point, dest_p);
1094
- }
1095
-
1096
- JERRY_ASSERT (required_buffer_size == (bytes_copied1 + bytes_copied2 -
1097
- (string_desc_p->u .concatenation .is_surrogate_pair_sliced
1098
- ? LIT_UTF8_CESU8_SURROGATE_SIZE_DIF
1099
- : 0 )));
1100
-
1101
- break ;
1102
- }
1103
1022
case ECMA_STRING_CONTAINER_MAGIC_STRING:
1104
1023
{
1105
1024
const lit_magic_string_id_t id = string_desc_p->u .magic_string_id ;
@@ -1210,11 +1129,6 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
1210
1129
1211
1130
return ecma_compare_chars_collection (chars_collection1_p, chars_collection2_p);
1212
1131
}
1213
- case ECMA_STRING_CONTAINER_CONCATENATION:
1214
- {
1215
- /* long path */
1216
- break ;
1217
- }
1218
1132
case ECMA_STRING_CONTAINER_LIT_TABLE:
1219
1133
{
1220
1134
JERRY_ASSERT (string1_p->u .lit_cp .packed_value != string2_p->u .lit_cp .packed_value );
@@ -1469,25 +1383,15 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
1469
1383
1470
1384
return (ecma_length_t ) ecma_number_to_utf8_string (*num_p, buffer, sizeof (buffer));
1471
1385
}
1472
- else if (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS)
1386
+ else
1473
1387
{
1388
+ JERRY_ASSERT (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
1389
+
1474
1390
const ecma_collection_header_t *collection_header_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t ,
1475
1391
string_p->u .collection_cp );
1476
1392
1477
1393
return ecma_get_chars_collection_length (collection_header_p);
1478
1394
}
1479
- else
1480
- {
1481
- JERRY_ASSERT (container == ECMA_STRING_CONTAINER_CONCATENATION);
1482
-
1483
- const ecma_string_t *string1_p, *string2_p;
1484
-
1485
- string1_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_p->u .concatenation .string1_cp );
1486
- string2_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_p->u .concatenation .string2_cp );
1487
-
1488
- return (ecma_string_get_length (string1_p) + ecma_string_get_length (string2_p) -
1489
- string_p->u .concatenation .is_surrogate_pair_sliced );
1490
- }
1491
1395
} /* ecma_string_get_length */
1492
1396
1493
1397
@@ -1555,27 +1459,15 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
1555
1459
buffer,
1556
1460
sizeof (buffer));
1557
1461
}
1558
- else if (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS)
1462
+ else
1559
1463
{
1464
+ JERRY_ASSERT (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
1465
+
1560
1466
const ecma_collection_header_t *collection_header_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t ,
1561
1467
string_p->u .collection_cp );
1562
1468
1563
1469
return collection_header_p->unit_number ;
1564
1470
}
1565
- else
1566
- {
1567
- JERRY_ASSERT (container == ECMA_STRING_CONTAINER_CONCATENATION);
1568
-
1569
- const ecma_string_t *string1_p, *string2_p;
1570
-
1571
- string1_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_p->u .concatenation .string1_cp );
1572
- string2_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t , string_p->u .concatenation .string2_cp );
1573
-
1574
- return (ecma_string_get_size (string1_p) + ecma_string_get_size (string2_p) -
1575
- (lit_utf8_size_t ) (string_p->u .concatenation .is_surrogate_pair_sliced
1576
- ? LIT_UTF8_CESU8_SURROGATE_SIZE_DIF
1577
- : 0 ));
1578
- }
1579
1471
} /* ecma_string_get_size */
1580
1472
1581
1473
/* *
@@ -1715,11 +1607,6 @@ ecma_is_string_magic (const ecma_string_t *string_p, /**< ecma-string */
1715
1607
1716
1608
return true ;
1717
1609
}
1718
- else if (string_p->container == ECMA_STRING_CONTAINER_CONCATENATION
1719
- && ecma_string_get_length (string_p) <= LIT_MAGIC_STRING_LENGTH_LIMIT)
1720
- {
1721
- return ecma_is_string_magic_longpath (string_p, out_id_p);
1722
- }
1723
1610
else
1724
1611
{
1725
1612
/*
@@ -1753,11 +1640,6 @@ ecma_is_ex_string_magic (const ecma_string_t *string_p, /**< ecma-string */
1753
1640
1754
1641
return true ;
1755
1642
}
1756
- else if (string_p->container == ECMA_STRING_CONTAINER_CONCATENATION
1757
- && ecma_string_get_length (string_p) <= LIT_MAGIC_STRING_LENGTH_LIMIT)
1758
- {
1759
- return ecma_is_ex_string_magic_longpath (string_p, out_id_p);
1760
- }
1761
1643
else
1762
1644
{
1763
1645
/*
0 commit comments