@@ -1270,28 +1270,6 @@ ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, /**< ecma-string
1270
1270
JERRY_ASSERT (size == buffer_size );
1271
1271
} /* ecma_string_to_utf8_bytes */
1272
1272
1273
- /**
1274
- * Lengths for numeric string values
1275
- */
1276
- static const uint32_t nums_with_ascending_length [] =
1277
- {
1278
- 1u ,
1279
- 10u ,
1280
- 100u ,
1281
- 1000u ,
1282
- 10000u ,
1283
- 100000u ,
1284
- 1000000u ,
1285
- 10000000u ,
1286
- 100000000u ,
1287
- 1000000000u
1288
- };
1289
-
1290
- /**
1291
- * Maximum length of numeric strings
1292
- */
1293
- static const uint32_t max_uint32_len = (uint32_t ) (sizeof (nums_with_ascending_length ) / sizeof (uint32_t ));
1294
-
1295
1273
/**
1296
1274
* Get size of the number stored locally in the string's descriptor
1297
1275
*
@@ -1302,12 +1280,24 @@ static const uint32_t max_uint32_len = (uint32_t) (sizeof (nums_with_ascending_l
1302
1280
static inline ecma_length_t __attr_always_inline___
1303
1281
ecma_string_get_number_in_desc_size (const uint32_t uint32_number ) /**< number in the string-descriptor */
1304
1282
{
1283
+ uint32_t prev_number = 1 ;
1284
+ uint32_t next_number = 100 ;
1305
1285
ecma_length_t size = 1 ;
1306
1286
1307
- while (size < max_uint32_len && uint32_number >= nums_with_ascending_length [size ])
1287
+ const uint32_t max_size = 9 ;
1288
+
1289
+ while (size < max_size && uint32_number >= next_number )
1290
+ {
1291
+ prev_number = next_number ;
1292
+ next_number *= 100 ;
1293
+ size += 2 ;
1294
+ }
1295
+
1296
+ if (uint32_number >= prev_number * 10 )
1308
1297
{
1309
1298
size ++ ;
1310
1299
}
1300
+
1311
1301
return size ;
1312
1302
} /* ecma_string_get_number_in_desc_size */
1313
1303
@@ -1317,13 +1307,17 @@ ecma_string_get_number_in_desc_size (const uint32_t uint32_number) /**< number i
1317
1307
#define ECMA_STRING_IS_ASCII (char_p , size ) ((size) == lit_utf8_string_length ((char_p), (size)))
1318
1308
1319
1309
/**
1320
- * Returns with the raw byte array of the string, if it is available .
1310
+ * Returns with the cesu8 character array of a string.
1321
1311
*
1322
- * @return byte array start - if the byte array of a string is available
1323
- * NULL - otherwise
1312
+ * Note:
1313
+ * This function returns with NULL for uint32 strings.
1314
+ * The buffer size is rounded up to 8 in this case.
1315
+ *
1316
+ * @return NULL - for uint32 strings
1317
+ * start of cesu8 characters - otherwise
1324
1318
*/
1325
1319
const lit_utf8_byte_t *
1326
- ecma_string_raw_chars (const ecma_string_t * string_p , /**< ecma-string */
1320
+ ecma_string_get_chars (const ecma_string_t * string_p , /**< ecma-string */
1327
1321
lit_utf8_size_t * size_p , /**< [out] size of the ecma string */
1328
1322
bool * is_ascii_p ) /**< [out] true, if the string is an ascii
1329
1323
* character sequence (size == length)
@@ -1377,18 +1371,27 @@ ecma_string_raw_chars (const ecma_string_t *string_p, /**< ecma-string */
1377
1371
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p ) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX );
1378
1372
1379
1373
size = lit_get_magic_string_ex_size (string_p -> u .magic_string_ex_id );
1380
- length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p -> u .magic_string_ex_id ),
1381
- 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
+ }
1382
1381
1383
1382
result_p = lit_get_magic_string_ex_utf8 (string_p -> u .magic_string_ex_id );
1384
1383
break ;
1385
1384
}
1386
1385
}
1387
1386
1388
1387
* size_p = size ;
1389
- * is_ascii_p = (length == size );
1388
+
1389
+ if (is_ascii_p != NULL )
1390
+ {
1391
+ * is_ascii_p = (length == size );
1392
+ }
1390
1393
return result_p ;
1391
- } /* ecma_string_raw_chars */
1394
+ } /* ecma_string_get_chars */
1392
1395
1393
1396
/**
1394
1397
* Checks whether the string equals to the magic string id.
@@ -1977,7 +1980,7 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
1977
1980
1978
1981
lit_utf8_size_t buffer_size ;
1979
1982
bool is_ascii ;
1980
- const lit_utf8_byte_t * chars_p = ecma_string_raw_chars (string_p , & buffer_size , & is_ascii );
1983
+ const lit_utf8_byte_t * chars_p = ecma_string_get_chars (string_p , & buffer_size , & is_ascii );
1981
1984
1982
1985
if (chars_p != NULL )
1983
1986
{
@@ -1996,7 +1999,7 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
1996
1999
ecma_string_to_utf8_bytes (string_p , utf8_str_p , buffer_size );
1997
2000
1998
2001
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p ) == ECMA_STRING_CONTAINER_UINT32_IN_DESC );
1999
- /* Both above must be ascii strings . */
2002
+ /* Uint32 must be an ascii string . */
2000
2003
JERRY_ASSERT (is_ascii );
2001
2004
2002
2005
ch = utf8_str_p [index ];
0 commit comments