Skip to content

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

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

LaszloLango
Copy link
Contributor

JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]

@LaszloLango LaszloLango added enhancement An improvement binary size Affects binary size labels Feb 20, 2018
@LaszloLango
Copy link
Contributor Author

Binary sizes (bytes)
6fce323:134344
c5c5db8:133852

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));
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

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);
Copy link
Member

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 */
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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, ..

Copy link
Member

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

Copy link
Contributor Author

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


#define ECMA_STRING_FLAG_EMPTY 0u
#define ECMA_STRING_FLAG_IS_ASCII 1u
#define ECMA_STRING_FLAG_MUST_BE_FREED 2u
Copy link
Member

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.

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

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

What is this definition?

Copy link
Contributor Author

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

@LaszloLango LaszloLango force-pushed the string-dev branch 3 times, most recently from 2d98111 to 8ff6b1b Compare February 22, 2018 10:46
@LaszloLango
Copy link
Contributor Author

@zherczeg thanks for the review. I've updated the PR.

@LaszloLango
Copy link
Contributor Author

@zherczeg rebased to the current master. The measurement results are still good on RPi2. There is no negative side effect of the patch.

Copy link
Member

@zherczeg zherczeg left a 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;
Copy link
Member

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.

/**
* 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 */ \
Copy link
Member

Choose a reason for hiding this comment

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

in ???

Copy link
Contributor Author

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.

@LaszloLango
Copy link
Contributor Author

@zherczeg Thanks for the review. I've updated the PR.

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@dbatyai dbatyai left a comment

Choose a reason for hiding this comment

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

LGTM

@dbatyai dbatyai merged commit e10f6d6 into jerryscript-project:master Feb 27, 2018
grgustaf pushed a commit to grgustaf/jerryscript that referenced this pull request Mar 19, 2018
@LaszloLango LaszloLango deleted the string-dev branch May 10, 2018 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary size Affects binary size enhancement An improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants