Skip to content

Commit 3b0f61a

Browse files
kkristofLaszloLango
authored andcommitted
Remove ECMA_STRING_CONTAINER_CONCATENATION type from ecma_string
JerryScript-DCO-1.0-Signed-off-by: Kristof Kosztyo kkosztyo.u-szeged@partner.samsung.com
1 parent 6697523 commit 3b0f61a

File tree

2 files changed

+30
-162
lines changed

2 files changed

+30
-162
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ typedef enum
783783
ECMA_STRING_CONTAINER_HEAP_NUMBER, /**< actual data is on the heap as a ecma_number_t */
784784
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
785785
stored locally in the string's descriptor */
786-
ECMA_STRING_CONTAINER_CONCATENATION, /**< the ecma-string is concatenation of two specified ecma-strings */
787786
ECMA_STRING_CONTAINER_MAGIC_STRING, /**< the ecma-string is equal to one of ECMA magic strings */
788787
ECMA_STRING_CONTAINER_MAGIC_STRING_EX /**< the ecma-string is equal to one of external magic strings */
789788
} ecma_string_container_t;
@@ -831,19 +830,6 @@ typedef struct ecma_string_t
831830
/** UInt32-represented number placed locally in the descriptor */
832831
uint32_t uint32_number;
833832

834-
/** Representation of concatenation */
835-
struct
836-
{
837-
mem_cpointer_t string1_cp : ECMA_POINTER_FIELD_WIDTH;
838-
mem_cpointer_t string2_cp : ECMA_POINTER_FIELD_WIDTH;
839-
840-
/**
841-
* Flag indicating that last code_unit of first string in concatenation is high surrogate
842-
* and first code_unit of second string is low surrogate
843-
*/
844-
unsigned int is_surrogate_pair_sliced : 1;
845-
} concatenation;
846-
847833
/** Identifier of magic string */
848834
lit_magic_string_id_t magic_string_id;
849835

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 30 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -627,53 +627,44 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
627627
jerry_fatal (ERR_OUT_OF_MEMORY);
628628
}
629629

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-
643630
ecma_char_t str1_last_code_unit = ecma_string_get_char_at_pos (string1_p, ecma_string_get_length (string1_p) - 1);
644631
ecma_char_t str2_first_code_unit = ecma_string_get_char_at_pos (string2_p, 0);
645632

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));
648635

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);
652638

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);
654640

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;
657642

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);
659645

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);
661650
}
662651
else
663652
{
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);
667658

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);
674662
}
663+
ecma_string_t *str_concat_p = ecma_new_ecma_string_from_utf8 (str_p, buffer_size);
675664

676-
return string_desc_p;
665+
mem_heap_free_block ((void*) str_p);
666+
667+
return str_concat_p;
677668
} /* ecma_concat_ecma_strings */
678669

679670
/**
@@ -706,16 +697,6 @@ ecma_copy_ecma_string (ecma_string_t *string_desc_p) /**< string descriptor */
706697
break;
707698
}
708699

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-
719700
case ECMA_STRING_CONTAINER_HEAP_NUMBER:
720701
{
721702
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 */
840821

841822
break;
842823
}
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-
}
857824
case ECMA_STRING_CONTAINER_LIT_TABLE:
858825
case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
859826
case ECMA_STRING_CONTAINER_MAGIC_STRING:
@@ -924,7 +891,6 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
924891

925892
case ECMA_STRING_CONTAINER_LIT_TABLE:
926893
case ECMA_STRING_CONTAINER_HEAP_CHUNKS:
927-
case ECMA_STRING_CONTAINER_CONCATENATION:
928894
case ECMA_STRING_CONTAINER_MAGIC_STRING:
929895
case ECMA_STRING_CONTAINER_MAGIC_STRING_EX:
930896
{
@@ -1052,54 +1018,7 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
10521018

10531019
break;
10541020
}
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);
10701021

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-
}
11031022
case ECMA_STRING_CONTAINER_MAGIC_STRING:
11041023
{
11051024
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
12101129

12111130
return ecma_compare_chars_collection (chars_collection1_p, chars_collection2_p);
12121131
}
1213-
case ECMA_STRING_CONTAINER_CONCATENATION:
1214-
{
1215-
/* long path */
1216-
break;
1217-
}
12181132
case ECMA_STRING_CONTAINER_LIT_TABLE:
12191133
{
12201134
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 */
14691383

14701384
return (ecma_length_t) ecma_number_to_utf8_string (*num_p, buffer, sizeof (buffer));
14711385
}
1472-
else if (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS)
1386+
else
14731387
{
1388+
JERRY_ASSERT (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
1389+
14741390
const ecma_collection_header_t *collection_header_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t,
14751391
string_p->u.collection_cp);
14761392

14771393
return ecma_get_chars_collection_length (collection_header_p);
14781394
}
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-
}
14911395
} /* ecma_string_get_length */
14921396

14931397

@@ -1555,27 +1459,15 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
15551459
buffer,
15561460
sizeof (buffer));
15571461
}
1558-
else if (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS)
1462+
else
15591463
{
1464+
JERRY_ASSERT (container == ECMA_STRING_CONTAINER_HEAP_CHUNKS);
1465+
15601466
const ecma_collection_header_t *collection_header_p = ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t,
15611467
string_p->u.collection_cp);
15621468

15631469
return collection_header_p->unit_number;
15641470
}
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-
}
15791471
} /* ecma_string_get_size */
15801472

15811473
/**
@@ -1715,11 +1607,6 @@ ecma_is_string_magic (const ecma_string_t *string_p, /**< ecma-string */
17151607

17161608
return true;
17171609
}
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-
}
17231610
else
17241611
{
17251612
/*
@@ -1753,11 +1640,6 @@ ecma_is_ex_string_magic (const ecma_string_t *string_p, /**< ecma-string */
17531640

17541641
return true;
17551642
}
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-
}
17611643
else
17621644
{
17631645
/*

0 commit comments

Comments
 (0)