Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions jerry-core/lit/lit-strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ lit_utf8_string_code_unit_at (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 stri
return code_unit;
} /* lit_utf8_string_code_unit_at */

/* CESU-8 number of bytes occupied lookup table */
const __attribute__ ((aligned (CESU_8_TABLE_MEM_ALIGNMENT))) lit_utf8_byte_t table[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the alignment attribute?

{
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0,
2, 2,
3, 0
};

/**
* Get CESU-8 encoded size of character
*
Expand All @@ -765,19 +774,14 @@ lit_utf8_string_code_unit_at (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 stri
lit_utf8_size_t
lit_get_unicode_char_size_by_utf8_first_byte (const lit_utf8_byte_t first_byte) /**< buffer with characters */
{
if ((first_byte & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER)
{
return 1;
}
else if ((first_byte & LIT_UTF8_2_BYTE_MASK) == LIT_UTF8_2_BYTE_MARKER)
{
return 2;
}
else
{
JERRY_ASSERT ((first_byte & LIT_UTF8_3_BYTE_MASK) == LIT_UTF8_3_BYTE_MARKER);
return 3;
}
JERRY_ASSERT (((first_byte >> 4) == 0 ||
(first_byte >> 4) == 1 || (first_byte >> 4) == 2 ||
(first_byte >> 4) == 3 || (first_byte >> 4) == 4 ||
(first_byte >> 4) == 5 || (first_byte >> 4) == 6 ||
(first_byte >> 4) == 7 || (first_byte >> 4) == 12 ||
(first_byte >> 4) == 13 || (first_byte >> 4) == 14));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no objection against big asserts, but in this case wouldn't be better to use (first_byte >> 4) <= 7 ? This is just a note, so if others prefer the current one, it is ok for me.


return table[first_byte >> 4];
} /* lit_get_unicode_char_size_by_utf8_first_byte */

/**
Expand Down
1 change: 1 addition & 0 deletions jerry-core/lit/lit-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ lit_string_hash_t lit_utf8_string_calc_hash (const lit_utf8_byte_t *, lit_utf8_s
lit_string_hash_t lit_utf8_string_hash_combine (lit_string_hash_t, const lit_utf8_byte_t *, lit_utf8_size_t);

/* code unit access */
#define CESU_8_TABLE_MEM_ALIGNMENT 16
ecma_char_t lit_utf8_string_code_unit_at (const lit_utf8_byte_t *, lit_utf8_size_t, ecma_length_t);
lit_utf8_size_t lit_get_unicode_char_size_by_utf8_first_byte (lit_utf8_byte_t);

Expand Down