Skip to content
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

Introduce JERRY_ZSTR_ARG macro to avoid call strlen on string literal. #4982

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

lygstate
Copy link
Contributor

@lygstate lygstate commented Feb 10, 2022

Currently jerryx_print_string ("\\u0000") are implementd with

void
jerryx_print_string (const char *str_p)
{
  const jerry_char_t *buffer_p = (jerry_char_t *) str_p;
  jerry_size_t buffer_size = (jerry_size_t) (strlen (str_p));

  jerry_port_print_buffer (buffer_p, buffer_size);
#if JERRY_DEBUGGER
  jerry_debugger_send_output (buffer_p, buffer_size);
#endif /* JERRY_DEBUGGER */
} /* jerryx_print_string */

So indeed "\u0000" is not output before MR, after this MR, jerryx_print_string is removed, and jerryx_print_string ("\\u0000") replaced with jerryx_print_buffer (JERRY_ZSTR_ARG ("\\u0000"));, so the string "\u0000" is output to console after this MR.

  • replace usage of jerryx_print_byte with jerryx_print_buffer.

So we only need implement jerry_port_print_buffer, reduce the code size and port api list

Partially fixes #4979

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]

@LaszloLango LaszloLango added this to the Release 3.0.0 milestone Nov 13, 2024
@LaszloLango LaszloLango added the enhancement An improvement label Nov 13, 2024
@lygstate lygstate force-pushed the zstr_macro branch 8 times, most recently from e1a19d2 to 5483007 Compare November 14, 2024 09:02
Copy link
Contributor

@robertsipka robertsipka left a comment

Choose a reason for hiding this comment

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

LGTM

@lygstate
Copy link
Contributor Author

@ossy-szeged

…rint_byte, jerry_port_print_byte, strlen

Replace usage of jerryx_print_byte, jerryx_print_string with jerryx_print_buffer.

As we now have JERRY_ZSTR_ARG, so we can take advantage of it

With this, the jerry_port_print_byte port api won't need any more
this reduced the port api surface

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

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

LGTM

@robertsipka robertsipka merged commit dfa9afb into jerryscript-project:master Nov 25, 2024
26 checks passed
@lygstate lygstate deleted the zstr_macro branch December 2, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature, strlen are rarely called in jerry-core and jerry-ext, we can remove all the usage of strlen
3 participants