mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Optimize uint32 hash computation.
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
parent
71c32a1d96
commit
a5d9701f60
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user