diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2024-04-16 20:30:48 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2024-04-25 15:15:09 +0100 |
commit | 8f861cf4d15e8befca6edcee4b04b5304f082f05 (patch) | |
tree | d1f4bfd3386e6d5a149deb1e164bc2b68b6f3bda /src/nxt_js.c | |
parent | e5bc299d7a55a66e1ecf54d35dcdd9448c49f3d4 (diff) | |
download | unit-8f861cf4d15e8befca6edcee4b04b5304f082f05.tar.gz unit-8f861cf4d15e8befca6edcee4b04b5304f082f05.tar.bz2 |
Constify a bunch of static local variables
A common pattern was to declare variables in functions like
static nxt_str_t ...
Not sure why static, as they were being treated more like string
literals (and of course they are _not_ thread safe), let's actually make
them constants (qualifier wise).
This handles core code conversion.
Reviewed-by: Zhidao HONG <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/nxt_js.c')
-rw-r--r-- | src/nxt_js.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/nxt_js.c b/src/nxt_js.c index 1f9a3ceb..d46231bd 100644 --- a/src/nxt_js.c +++ b/src/nxt_js.c @@ -124,9 +124,9 @@ nxt_js_vm_create(nxt_js_conf_t *jcf) njs_vm_opt_t opts; nxt_js_module_t *module, *mod; - static nxt_str_t import_str = nxt_string("import"); - static nxt_str_t from_str = nxt_string("from"); - static nxt_str_t global_str = nxt_string("globalThis"); + static const nxt_str_t import_str = nxt_string("import"); + static const nxt_str_t from_str = nxt_string("from"); + static const nxt_str_t global_str = nxt_string("globalThis"); njs_vm_opt_init(&opts); @@ -237,14 +237,15 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz) nxt_js_t *js; nxt_str_t *func; - static nxt_str_t func_str = nxt_string("function(uri, host, remoteAddr, " - "args, headers, cookies, vars) {" - " return "); + static const nxt_str_t func_str = + nxt_string("function(uri, host, remoteAddr, " + "args, headers, cookies, vars) {" + " return "); /* * Appending a terminating null character if strz is true. */ - static nxt_str_t strz_str = nxt_string(" + '\\x00'"); + static const nxt_str_t strz_str = nxt_string(" + '\\x00'"); size = func_str.length + str->length + 1; |