Skip to content

Commit e8c60b5

Browse files
committed
Remove unnecessary variable length arrays.
VLAs cannot be initialized by any form of initialization syntax with C99 standard. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
1 parent 0219f37 commit e8c60b5

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

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

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,26 +1316,12 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
13161316
else if (container == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
13171317
{
13181318
const uint32_t uint32_number = string_p->u.uint32_number;
1319-
const uint32_t max_uint32_len = 10;
1320-
const uint32_t nums_with_ascending_length[10] =
1321-
{
1322-
1u,
1323-
10u,
1324-
100u,
1325-
1000u,
1326-
10000u,
1327-
100000u,
1328-
1000000u,
1329-
10000000u,
1330-
100000000u,
1331-
1000000000u
1332-
};
1333-
1334-
ecma_length_t length = 1;
1335-
1336-
while (length < max_uint32_len
1337-
&& uint32_number >= nums_with_ascending_length[length])
1319+
const ecma_length_t max_uint32_len = 10u;
1320+
ecma_length_t nums_with_ascending_length = 10u;
1321+
ecma_length_t length = 1u;
1322+
while ((length < max_uint32_len) && (uint32_number >= nums_with_ascending_length))
13381323
{
1324+
nums_with_ascending_length *= 10u;
13391325
length++;
13401326
}
13411327

@@ -1390,25 +1376,13 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
13901376
case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
13911377
{
13921378
const uint32_t uint32_number = string_p->u.uint32_number;
1393-
const int32_t max_uint32_len = 10;
1394-
const uint32_t nums_with_ascending_length[max_uint32_len] =
1395-
{
1396-
1u,
1397-
10u,
1398-
100u,
1399-
1000u,
1400-
10000u,
1401-
100000u,
1402-
1000000u,
1403-
10000000u,
1404-
100000000u,
1405-
1000000000u
1406-
};
1407-
1408-
int32_t size = 1;
1409-
while (size < max_uint32_len
1410-
&& uint32_number >= nums_with_ascending_length[size])
1379+
const ecma_length_t max_uint32_len = 10u;
1380+
ecma_length_t nums_with_ascending_length = 10u;
1381+
ecma_length_t size = 1u;
1382+
1383+
while ((size < max_uint32_len) && (uint32_number >= nums_with_ascending_length))
14111384
{
1385+
nums_with_ascending_length *= 10u;
14121386
size++;
14131387
}
14141388
return (lit_utf8_size_t) size;

0 commit comments

Comments
 (0)