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:
Akos Kiss
2018-09-17 10:07:24 +02:00
committed by László Langó
parent 2d83d8ed17
commit 3d3a8008a8
24 changed files with 367 additions and 389 deletions
+9 -7
View File
@@ -49,11 +49,11 @@ main (void)
int countdown = 6;
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
const char *inf_loop_code_src_p = "while(true) {}";
const jerry_char_t inf_loop_code_src1[] = "while(true) {}";
jerry_value_t parsed_code_val = jerry_parse (NULL,
0,
(jerry_char_t *) inf_loop_code_src_p,
strlen (inf_loop_code_src_p),
inf_loop_code_src1,
sizeof (inf_loop_code_src1) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
@@ -71,13 +71,15 @@ main (void)
/* We keep the callback function, only the countdown is reset. */
countdown = 6;
inf_loop_code_src_p = ("function f() { while (true) ; }\n"
"try { f(); } catch(e) {}");
const jerry_char_t inf_loop_code_src2[] = TEST_STRING_LITERAL (
"function f() { while (true) ; }\n"
"try { f(); } catch(e) {}"
);
parsed_code_val = jerry_parse (NULL,
0,
(jerry_char_t *) inf_loop_code_src_p,
strlen (inf_loop_code_src_p),
inf_loop_code_src2,
sizeof (inf_loop_code_src2) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));