diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index 3e1f3b5ab..170e4c5bc 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -734,7 +734,7 @@ typedef double ecma_number_t; /** * Maximum number of characters in string representation of ecma-uint32 */ -#define ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 32 +#define ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 10 /** * Maximum value of valid array index diff --git a/jerry-core/ecma/base/ecma-helpers-conversion.c b/jerry-core/ecma/base/ecma-helpers-conversion.c index fc294f83f..d741d734b 100644 --- a/jerry-core/ecma/base/ecma-helpers-conversion.c +++ b/jerry-core/ecma/base/ecma-helpers-conversion.c @@ -783,29 +783,25 @@ ecma_uint32_to_utf8_string (uint32_t value, /**< value to convert */ lit_utf8_byte_t *out_buffer_p, /**< buffer for string */ lit_utf8_size_t buffer_size) /**< size of buffer */ { - const lit_utf8_byte_t digits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; - - lit_utf8_byte_t *p = out_buffer_p + buffer_size - 1; - lit_utf8_size_t bytes_copied = 0; + lit_utf8_byte_t *buf_p = out_buffer_p + buffer_size; do { - JERRY_ASSERT (p >= out_buffer_p); + JERRY_ASSERT (buf_p >= out_buffer_p); - *p-- = digits[value % 10]; + buf_p--; + *buf_p = (lit_utf8_byte_t) ((value % 10) + LIT_CHAR_0); value /= 10; - - bytes_copied++; } while (value != 0); - p++; + JERRY_ASSERT (buf_p >= out_buffer_p); - JERRY_ASSERT (p >= out_buffer_p); + lit_utf8_size_t bytes_copied = (lit_utf8_size_t) (out_buffer_p + buffer_size - buf_p); - if (likely (p != out_buffer_p)) + if (likely (buf_p != out_buffer_p)) { - memmove (out_buffer_p, p, bytes_copied); + memmove (out_buffer_p, buf_p, bytes_copied); } return bytes_copied; diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index f64cfffcc..79c60f916 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -229,15 +229,25 @@ ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit) /**< code unit */ ecma_string_t * ecma_new_ecma_string_from_uint32 (uint32_t uint32_number) /**< UInt32-represented ecma-number */ { + lit_utf8_byte_t byte_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; + lit_utf8_byte_t *buf_p = byte_buf + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32; + + uint32_t value = uint32_number; + do + { + JERRY_ASSERT (buf_p >= byte_buf); + + buf_p--; + *buf_p = (lit_utf8_byte_t) ((value % 10) + LIT_CHAR_0); + value /= 10; + } + while (value != 0); + + lit_utf8_size_t size = (lit_utf8_size_t) (byte_buf + ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 - buf_p); + ecma_string_t *string_desc_p = ecma_alloc_string (); string_desc_p->refs_and_container = ECMA_STRING_CONTAINER_UINT32_IN_DESC | ECMA_STRING_REF_ONE; - - lit_utf8_byte_t byte_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32]; - lit_utf8_size_t bytes_copied = ecma_uint32_to_utf8_string (uint32_number, - byte_buf, - ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32); - - string_desc_p->hash = lit_utf8_string_calc_hash (byte_buf, bytes_copied); + string_desc_p->hash = lit_utf8_string_calc_hash (buf_p, size); string_desc_p->u.common_field = 0; string_desc_p->u.uint32_number = uint32_number;