@@ -395,10 +395,8 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
395395 string_desc_p -> refs_and_container = ECMA_STRING_CONTAINER_HEAP_ASCII_STRING | ECMA_STRING_REF_ONE ;
396396 const size_t data_size = new_size ;
397397 lit_utf8_byte_t * data_p = (lit_utf8_byte_t * ) jmem_heap_alloc_block (data_size );
398- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string1_p , data_p , str1_size );
399- JERRY_ASSERT (bytes_copied == str1_size );
400- bytes_copied = ecma_string_to_utf8_string (string2_p , data_p + str1_size , str2_size );
401- JERRY_ASSERT (bytes_copied == str2_size );
398+ ecma_string_to_utf8_bytes (string1_p , data_p , str1_size );
399+ ecma_string_to_utf8_bytes (string2_p , data_p + str1_size , str2_size );
402400
403401 string_desc_p -> u .ascii_string .size = (uint16_t ) new_size ;
404402
@@ -411,15 +409,14 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
411409 string_desc_p -> refs_and_container = ECMA_STRING_CONTAINER_HEAP_UTF8_STRING | ECMA_STRING_REF_ONE ;
412410 const size_t data_size = new_size + sizeof (ecma_string_heap_header_t );
413411 ecma_string_heap_header_t * data_p = (ecma_string_heap_header_t * ) jmem_heap_alloc_block (data_size );
414- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string1_p ,
415- (lit_utf8_byte_t * ) (data_p + 1 ),
416- str1_size );
417- JERRY_ASSERT (bytes_copied == str1_size );
418-
419- bytes_copied = ecma_string_to_utf8_string (string2_p ,
420- (lit_utf8_byte_t * ) (data_p + 1 ) + str1_size ,
421- str2_size );
422- JERRY_ASSERT (bytes_copied == str2_size );
412+ ecma_string_to_utf8_bytes (string1_p ,
413+ (lit_utf8_byte_t * ) (data_p + 1 ),
414+ str1_size );
415+
416+ ecma_string_to_utf8_bytes (string2_p ,
417+ (lit_utf8_byte_t * ) (data_p + 1 ) + str1_size ,
418+ str2_size );
419+
423420 JERRY_ASSERT (string_length <= UINT16_MAX );
424421
425422 data_p -> size = (uint16_t ) new_size ;
@@ -675,10 +672,10 @@ ecma_string_get_array_index (const ecma_string_t *str_p, /**< ecma-string */
675672 * @return number of bytes, actually copied to the buffer.
676673 */
677674lit_utf8_size_t __attr_return_value_should_be_checked___
678- ecma_string_to_utf8_string (const ecma_string_t * string_desc_p , /**< ecma-string descriptor */
679- lit_utf8_byte_t * buffer_p , /**< destination buffer pointer
680- * (can be NULL if buffer_size == 0) */
681- lit_utf8_size_t buffer_size ) /**< size of buffer */
675+ ecma_string_copy_to_utf8_buffer (const ecma_string_t * string_desc_p , /**< ecma-string descriptor */
676+ lit_utf8_byte_t * buffer_p , /**< destination buffer pointer
677+ * (can be NULL if buffer_size == 0) */
678+ lit_utf8_size_t buffer_size ) /**< size of buffer */
682679{
683680 JERRY_ASSERT (string_desc_p != NULL );
684681 JERRY_ASSERT (string_desc_p -> refs_and_container >= ECMA_STRING_REF_ONE );
@@ -741,7 +738,24 @@ ecma_string_to_utf8_string (const ecma_string_t *string_desc_p, /**< ecma-string
741738
742739 JERRY_ASSERT (size <= buffer_size );
743740 return size ;
744- } /* ecma_string_to_utf8_string */
741+ } /* ecma_string_copy_to_utf8_buffer */
742+
743+ /**
744+ * Convert ecma-string's contents to a cesu-8 string and put it to the buffer.
745+ * It is the caller's responsibility to make sure that the string fits in the buffer.
746+ * Check if the size of the string is equal with the size of the buffer.
747+ */
748+ void __attr_always_inline___
749+ ecma_string_to_utf8_bytes (const ecma_string_t * string_desc_p , /**< ecma-string descriptor */
750+ lit_utf8_byte_t * buffer_p , /**< destination buffer pointer
751+ * (can be NULL if buffer_size == 0) */
752+ lit_utf8_size_t buffer_size ) /**< size of buffer */
753+ {
754+ JERRY_ASSERT (ecma_string_get_size (string_desc_p ) == buffer_size );
755+
756+ lit_utf8_size_t size = ecma_string_copy_to_utf8_buffer (string_desc_p , buffer_p , buffer_size );
757+ JERRY_ASSERT (size == buffer_size );
758+ } /* ecma_string_to_utf8_bytes */
745759
746760/**
747761 * Lengths for numeric string values
@@ -1018,8 +1032,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
10181032 {
10191033 utf8_string1_p = (lit_utf8_byte_t * ) jmem_heap_alloc_block ((size_t ) strings_size );
10201034
1021- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string1_p , utf8_string1_p , strings_size );
1022- JERRY_ASSERT (bytes_copied == strings_size );
1035+ ecma_string_to_utf8_bytes (string1_p , utf8_string1_p , strings_size );
10231036
10241037 is_utf8_string1_on_heap = true;
10251038 }
@@ -1049,11 +1062,11 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
10491062 {
10501063 utf8_string2_p = (lit_utf8_byte_t * ) jmem_heap_alloc_block ((size_t ) strings_size );
10511064
1052- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string2_p , utf8_string2_p , strings_size );
1053- JERRY_ASSERT (bytes_copied == strings_size );
1065+ ecma_string_to_utf8_bytes (string2_p , utf8_string2_p , strings_size );
10541066
10551067 is_utf8_string2_on_heap = true;
10561068 }
1069+
10571070 const bool is_equal = !strncmp ((char * ) utf8_string1_p , (char * ) utf8_string2_p , (size_t ) strings_size );
10581071
10591072 if (is_utf8_string1_on_heap )
@@ -1160,8 +1173,7 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
11601173 utf8_string1_p = utf8_string1_buffer ;
11611174 }
11621175
1163- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string1_p , utf8_string1_p , utf8_string1_size );
1164- JERRY_ASSERT (bytes_copied == utf8_string1_size );
1176+ ecma_string_to_utf8_bytes (string1_p , utf8_string1_p , utf8_string1_size );
11651177 }
11661178
11671179 if (ECMA_STRING_GET_CONTAINER (string2_p ) == ECMA_STRING_CONTAINER_HEAP_UTF8_STRING )
@@ -1202,8 +1214,7 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
12021214 utf8_string2_p = utf8_string2_buffer ;
12031215 }
12041216
1205- lit_utf8_size_t bytes_copied = ecma_string_to_utf8_string (string2_p , utf8_string2_p , utf8_string2_size );
1206- JERRY_ASSERT (bytes_copied == utf8_string2_size );
1217+ ecma_string_to_utf8_bytes (string2_p , utf8_string2_p , utf8_string2_size );
12071218 }
12081219
12091220 bool is_first_less_than_second = lit_compare_utf8_strings_relational (utf8_string1_p ,
@@ -1345,8 +1356,7 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
13451356
13461357 JMEM_DEFINE_LOCAL_ARRAY (utf8_str_p , buffer_size , lit_utf8_byte_t );
13471358
1348- lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p , utf8_str_p , buffer_size );
1349- JERRY_ASSERT (sz == buffer_size );
1359+ ecma_string_to_utf8_bytes (string_p , utf8_str_p , buffer_size );
13501360
13511361 JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p ) == ECMA_STRING_CONTAINER_UINT32_IN_DESC );
13521362 /* Both above must be ascii strings. */
@@ -1504,8 +1514,7 @@ ecma_string_substr (const ecma_string_t *string_p, /**< pointer to an ecma strin
15041514
15051515 JMEM_DEFINE_LOCAL_ARRAY (utf8_str_p , buffer_size , lit_utf8_byte_t );
15061516
1507- lit_utf8_size_t sz = ecma_string_to_utf8_string (string_p , utf8_str_p , buffer_size );
1508- JERRY_ASSERT (sz == buffer_size );
1517+ ecma_string_to_utf8_bytes (string_p , utf8_str_p , buffer_size );
15091518
15101519 /**
15111520 * II. Extract substring
0 commit comments