-
Notifications
You must be signed in to change notification settings - Fork 684
Modified ecma string to utf8 string conversion to reduce binary size. #2214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1953394
to
4f06255
Compare
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id)); | ||
} | ||
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id), | ||
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see size
can be used instead of lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id)
like:
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id), size);
There would be one less function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
4f06255
to
a472a56
Compare
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id), | ||
lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id)); | ||
} | ||
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id), size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not remove this feature. Computing the length of a longer magic string takes time, which is unnecessary if we don't care about the ascii flag.
We could use the ASCII flag as an I/O flag, if it is not set, ascii check is ignored. Otherwise flag is cleared if not ascii. Or just use another flag for requesting an ascii check.
* false, otherwise */ | ||
uint8_t *flags_p) /**< [out] flags: 0 - empty, | ||
1 - is ascii, | ||
2 - must be freed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment is still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but I don't understand your question. I've updated the comments in my patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flags are ECMA_STRING_FLAG_EMPTY, ... not 0, 1, ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just mention the enum name of these flags, or their prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. I'll fix it. Thanks
jerry-core/ecma/base/ecma-helpers.h
Outdated
|
||
#define ECMA_STRING_FLAG_EMPTY 0u | ||
#define ECMA_STRING_FLAG_IS_ASCII 1u | ||
#define ECMA_STRING_FLAG_MUST_BE_FREED 2u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use an enum here, with proper comments.
jerry-core/ecma/base/ecma-helpers.h
Outdated
@@ -50,21 +50,33 @@ | |||
*/ | |||
#define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer) | |||
|
|||
bool ecma_string_to_utf8_string (const ecma_string_t *ecma_str_ptr, | |||
const lit_utf8_byte_t **utf8_ptr, | |||
lit_utf8_size_t *utf8_str_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover, I'll remove it
2d98111
to
8ff6b1b
Compare
@zherczeg thanks for the review. I've updated the PR. |
8ff6b1b
to
4571ede
Compare
@zherczeg rebased to the current master. The measurement results are still good on RPi2. There is no negative side effect of the patch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close to ready. I only have a few questions.
*is_ascii_p = (length == size); | ||
if (length != size) | ||
{ | ||
*flags_p &= (uint8_t) ~ECMA_STRING_FLAG_IS_ASCII; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually have trouble with such conversions on certain compilers.
jerry-core/ecma/base/ecma-helpers.h
Outdated
/** | ||
* Convert ecma-string's contents to a cesu-8 string and put it into a buffer. | ||
*/ | ||
#define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \ | ||
utf8_ptr, /**< [out] output buffer pointer */ \ | ||
utf8_str_size) /**< [out] output buffer size */ \ | ||
utf8_str_size) /**< [in,out] output buffer size */ \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidental change. I'll fix it.
4571ede
to
e1357b4
Compare
@zherczeg Thanks for the review. I've updated the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
e1357b4
to
c5a0d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…jerryscript-project#2214) JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]