@@ -1310,18 +1310,17 @@ ecma_string_get_number_in_desc_size (const uint32_t uint32_number) /**< number i
1310
1310
* Returns with the cesu8 character array of a string.
1311
1311
*
1312
1312
* Note:
1313
- * This function returns with NULL for uint32 strings.
1314
- * The buffer size is rounded up to 8 in this case .
1313
+ * This function returns with a newly allocated buffer for uint32 strings,
1314
+ * which must be freed .
1315
1315
*
1316
- * @return NULL - for uint32 strings
1317
- * start of cesu8 characters - otherwise
1316
+ * @return start of cesu8 characters
1318
1317
*/
1319
1318
const lit_utf8_byte_t *
1320
1319
ecma_string_get_chars (const ecma_string_t * string_p , /**< ecma-string */
1321
1320
lit_utf8_size_t * size_p , /**< [out] size of the ecma string */
1322
- bool * is_ascii_p ) /**< [out] true, if the string is an ascii
1323
- * character sequence (size == length)
1324
- * false, otherwise */
1321
+ uint8_t * flags_p ) /**< [out] flags: 0 - empty,
1322
+ 1 - is ascii,
1323
+ 2 - must be freed */
1325
1324
{
1326
1325
ecma_length_t length ;
1327
1326
lit_utf8_size_t size ;
@@ -1351,8 +1350,10 @@ ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */
1351
1350
/* All numbers must be ascii strings. */
1352
1351
JERRY_ASSERT (ecma_string_get_length (string_p ) == size );
1353
1352
1354
- length = size ;
1355
- result_p = NULL ;
1353
+ result_p = (const lit_utf8_byte_t * ) jmem_heap_alloc_block (size );
1354
+ length = ecma_uint32_to_utf8_string (string_p -> u .uint32_number , (lit_utf8_byte_t * ) result_p , size );
1355
+ JERRY_ASSERT (length == size );
1356
+ * flags_p |= ECMA_STRING_FLAG_MUST_BE_FREED ;
1356
1357
break ;
1357
1358
}
1358
1359
case ECMA_STRING_CONTAINER_MAGIC_STRING :
@@ -1371,13 +1372,8 @@ ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */
1371
1372
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p ) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX );
1372
1373
1373
1374
size = lit_get_magic_string_ex_size (string_p -> u .magic_string_ex_id );
1374
- length = 0 ;
1375
-
1376
- if (is_ascii_p != NULL )
1377
- {
1378
- length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p -> u .magic_string_ex_id ),
1379
- lit_get_magic_string_ex_size (string_p -> u .magic_string_ex_id ));
1380
- }
1375
+ length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p -> u .magic_string_ex_id ),
1376
+ lit_get_magic_string_ex_size (string_p -> u .magic_string_ex_id ));
1381
1377
1382
1378
result_p = lit_get_magic_string_ex_utf8 (string_p -> u .magic_string_ex_id );
1383
1379
break ;
@@ -1386,9 +1382,9 @@ ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */
1386
1382
1387
1383
* size_p = size ;
1388
1384
1389
- if (is_ascii_p != NULL )
1385
+ if (length == size )
1390
1386
{
1391
- * is_ascii_p = ( length == size ) ;
1387
+ * flags_p |= ECMA_STRING_FLAG_IS_ASCII ;
1392
1388
}
1393
1389
return result_p ;
1394
1390
} /* ecma_string_get_chars */
@@ -1979,32 +1975,23 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
1979
1975
JERRY_ASSERT (index < ecma_string_get_length (string_p ));
1980
1976
1981
1977
lit_utf8_size_t buffer_size ;
1982
- bool is_ascii ;
1983
- const lit_utf8_byte_t * chars_p = ecma_string_get_chars (string_p , & buffer_size , & is_ascii );
1978
+ uint8_t flags = ECMA_STRING_FLAG_EMPTY ;
1979
+ const lit_utf8_byte_t * chars_p = ecma_string_get_chars (string_p , & buffer_size , & flags );
1984
1980
1985
- if (chars_p != NULL )
1981
+ ecma_char_t ch ;
1982
+ if (flags & ECMA_STRING_FLAG_IS_ASCII )
1986
1983
{
1987
- if (is_ascii )
1988
- {
1989
- return chars_p [index ];
1990
- }
1991
-
1992
- return lit_utf8_string_code_unit_at (chars_p , buffer_size , index );
1984
+ ch = chars_p [index ];
1985
+ }
1986
+ else
1987
+ {
1988
+ ch = lit_utf8_string_code_unit_at (chars_p , buffer_size , index );
1993
1989
}
1994
1990
1995
- ecma_char_t ch ;
1996
-
1997
- JMEM_DEFINE_LOCAL_ARRAY (utf8_str_p , buffer_size , lit_utf8_byte_t );
1998
-
1999
- ecma_string_to_utf8_bytes (string_p , utf8_str_p , buffer_size );
2000
-
2001
- JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p ) == ECMA_STRING_CONTAINER_UINT32_IN_DESC );
2002
- /* Uint32 must be an ascii string. */
2003
- JERRY_ASSERT (is_ascii );
2004
-
2005
- ch = utf8_str_p [index ];
2006
-
2007
- JMEM_FINALIZE_LOCAL_ARRAY (utf8_str_p );
1991
+ if (flags & ECMA_STRING_FLAG_MUST_BE_FREED )
1992
+ {
1993
+ jmem_heap_free_block ((void * ) chars_p , buffer_size );
1994
+ }
2008
1995
2009
1996
return ch ;
2010
1997
} /* ecma_string_get_char_at_pos */
0 commit comments