Don't use strlen for string literals (#2517)
Their length (size) is known at compile time. Therefore `sizeof` is more efficient for them. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -395,9 +395,8 @@ int jerry_main (int argc, char *argv[])
|
||||
{
|
||||
printf ("No input files, running a hello world demo:\n");
|
||||
const jerry_char_t script[] = "var str = 'Hello World'; print(str + ' from JerryScript')";
|
||||
size_t script_size = strlen ((const char *) script);
|
||||
|
||||
ret_value = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
|
||||
ret_value = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
if (!jerry_value_is_error (ret_value))
|
||||
{
|
||||
|
||||
@@ -114,9 +114,7 @@ test_jerry ()
|
||||
test.delay(250); \
|
||||
";
|
||||
|
||||
size_t script_size = strlen ((const char *) script);
|
||||
|
||||
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
|
||||
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
/* Free JavaScript value, returned by eval */
|
||||
jerry_release_value (eval_ret);
|
||||
|
||||
@@ -56,7 +56,6 @@ int test_jerry (int argc, char **argv)
|
||||
jerry_value_t ret_value = jerry_create_undefined ();
|
||||
|
||||
const jerry_char_t script[] = "print ('Hello, World!');";
|
||||
size_t script_size = strlen ((const char *) script);
|
||||
printf ("This test run the following script code: [%s]\n\n", script);
|
||||
|
||||
/* Initialize engine */
|
||||
@@ -66,7 +65,7 @@ int test_jerry (int argc, char **argv)
|
||||
register_js_function ("print", jerryx_handler_print);
|
||||
|
||||
/* Setup Global scope code */
|
||||
ret_value = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
|
||||
ret_value = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
if (!jerry_value_is_error (ret_value))
|
||||
{
|
||||
|
||||
@@ -371,9 +371,8 @@ jerry_cmd_main (int argc, char *argv[])
|
||||
{
|
||||
printf ("No input files, running a hello world demo:\n");
|
||||
const jerry_char_t script[] = "var str = 'Hello World'; print(str + ' from JerryScript')";
|
||||
size_t script_size = strlen ((const char *) script);
|
||||
|
||||
ret_value = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
|
||||
ret_value = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
|
||||
|
||||
if (!jerry_value_is_error (ret_value))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user