Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reduce call to strlen when possible#5192

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
lygstate wants to merge1 commit intojerryscript-project:master
base:master
Choose a base branch
Loading
fromlygstate:strlen-reduced-all

Conversation

@lygstate
Copy link
Contributor

@lygstatelygstate commentedDec 9, 2024
edited
Loading

Closed:#4978
Closed:#4979

  • Improve jerry_string_sz only accept UTF-8 string(that's a rare case accept CESU-8 in c/cpp code)
  • The document about jerry_string_sz only support ASCII(the fact is CESU-8 before this MR), update it to support UTF-8 after this MR
  • Improve all _sz function to take jerry_value_t that can construct fromjerry_string_sz
  • Improve JERRY_ZSTR_ARG can only accept string literal(that's UTF-8)
  • Add function jerry_value_list_free to free a list of jerry_value_t
  • All call to jerry_string/jerry_string_cesu8 in core indeed are removed, so when there is no linkage to it, code size is saved

The prototype of new/improved function/macros is:

jerry_value_tjerry_string_cesu8 (constjerry_char_t*buffer_p,jerry_size_tbuffer_size);jerry_value_tjerry_string_utf8 (constjerry_char_t*buffer_p,jerry_size_tbuffer_size);#definejerry_string_sz(str) jerry_string_utf8 (JERRY_ZSTR_ARG (str))jerry_value_tjerry_error_sz (jerry_error_terror_type,constjerry_value_tmessage_sz);jerry_value_tjerry_regexp_sz (constjerry_value_tpattern_sz,uint16_tflags);jerry_value_tjerry_object_delete_sz (constjerry_value_tobject,constjerry_value_tkey_sz);jerry_value_tjerry_object_get_sz (constjerry_value_tobject,constjerry_value_tkey_sz);jerry_value_tjerry_object_has_sz (constjerry_value_tobject,constjerry_value_tkey_sz);jerry_value_tjerry_object_set_sz (jerry_value_tobject,constjerry_value_tkey_sz,constjerry_value_tvalue);

Rename jerry_port_log to jerry_port_log_buffer

Add buffer_size parameter for function jerry_port_log_buffer, so that jerry_port_log_buffer
won't need calculate strlen when printing

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luoluoyonggang@gmail.com

@zherczeg
Copy link
Member

What about keepingjerry_string_sz? Maybe addingjerry_string_utf8_sz()? I suspect cesu8/ascii is the same since ascii is 7 bit.

@lygstate
Copy link
ContributorAuthor

What about keepingjerry_string_sz? Maybe addingjerry_string_utf8_sz()? I suspect cesu8/ascii is the same since ascii is 7 bit.

jerry_string_sz is equal tojerry_sz_cesu8 andjerry_string_cesu8 before this MR,
we havejerry_sz_utf8 andjerry_string_utf8 that have the feature ofjerry_string_utf8_sz after this MR

jerry_sz_cesu8 is a macro for literal,
jerry_string_cesu8 is a function for ptr,length pair

@lygstate
Copy link
ContributorAuthor

I suspect cesu8/ascii is the same since ascii is 7 bit.
I have the willing to improve string#5182

So that refactoring ASCII out is a thing because for most/(maybe all) internal string is ASCII, and for ASCII the check function is much simpler.

The macro give us future optimize string literal store, asjerry_sz_ascii declered string can be in literal store

@zherczeg
Copy link
Member

Cesu8 is as efficient as ascii for checking, since the cpu branch predictor learns the simplest case. Two functions actually increase code size.

lygstate reacted with thumbs up emoji

@lygstate
Copy link
ContributorAuthor

Cesu8 is as efficient as ascii for checking, since the cpu branch predictor learns the simplest case. Two functions actually increase code size.

OK, I do the following to achieve the same effect, to code changes reduced a lot

  • Improve jerry_string_sz only accept UTF-8 string(that's a rare case accept CESU-8 in c/cpp code)
  • The document about jerry_string_sz only support ASCII(the fact is CESU-8 before this MR), update it to support UTF-8 after this MR

In summary jerry_string_sz preserved

@lygstatelygstateforce-pushed thestrlen-reduced-all branch 10 times, most recently frome7a63f4 to215c086CompareDecember 12, 2024 18:17
@lygstatelygstateforce-pushed thestrlen-reduced-all branch 2 times, most recently from80dba58 to466caeaCompareDecember 17, 2024 10:29
@lygstatelygstate mentioned this pull requestDec 17, 2024
* Improve jerry_string_sz only accept UTF-8 string(that's a rare case accept CESU-8 in c/cpp code)* The document about jerry_string_sz only support ASCII(the fact is CESU-8 before this MR), update it to support UTF-8 after this MR* Improve all _sz function to take jerry_value_t that can construct from `jerry_string_sz`* Improve JERRY_ZSTR_ARG can only accept string literal(that's UTF-8)* Add function jerry_value_list_free to free a list of jerry_value_t* All call to jerry_string/jerry_string_cesu8 in core indeed are removed, so when there is no linkage to it, code size is savedThe prototype of new/improved function/macros is:```cjerry_value_t jerry_string_cesu8 (const jerry_char_t *buffer_p, jerry_size_t buffer_size);jerry_value_t jerry_string_utf8 (const jerry_char_t *buffer_p, jerry_size_t buffer_size);#define jerry_string_sz(str) jerry_string_utf8 (JERRY_ZSTR_ARG (str))jerry_value_t jerry_error_sz (jerry_error_t error_type, const jerry_value_t message_sz);jerry_value_t jerry_throw_sz (jerry_error_t error_type, const jerry_value_t message_sz);jerry_value_t jerry_regexp_sz (const jerry_value_t pattern_sz, uint16_t flags);jerry_value_t jerry_object_delete_sz (const jerry_value_t object, const jerry_value_t key_sz);jerry_value_t jerry_object_get_sz (const jerry_value_t object, const jerry_value_t key_sz);jerry_value_t jerry_object_has_sz (const jerry_value_t object, const jerry_value_t key_sz);jerry_value_t jerry_object_set_sz (jerry_value_t object, const jerry_value_t key_sz, const jerry_value_t value);```JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

2 participants

@lygstate@zherczeg

[8]ページ先頭

©2009-2025 Movatter.jp