Anonymous User
October 08, 2024 07:06PM
details: https://github.com/nginx/njs/commit/3a4349e6b2b001001c64dd48f7863c5820cdf3e6
branches: master
commit: 3a4349e6b2b001001c64dd48f7863c5820cdf3e6
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon, 7 Oct 2024 22:41:24 -0700
description:
Optimized ngx_qjs_string().

Doing JS_IsString() check first before a heavy-weight call to
JS_GetTypedArrayBuffer() which throws an exception when argument is not
a typed array.

---
nginx/ngx_js.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c
index 5fe3dc84..98e48dc2 100644
--- a/nginx/ngx_js.c
+++ b/nginx/ngx_js.c
@@ -1472,6 +1472,10 @@ ngx_qjs_string(ngx_engine_t *e, JSValueConst val, ngx_str_t *dst)

cx = e->u.qjs.ctx;

+ if (JS_IsString(val)) {
+ goto string;
+ }
+
buffer = JS_GetTypedArrayBuffer(cx, val, &byte_offset, &byte_length, NULL);
if (!JS_IsException(buffer)) {
start = JS_GetArrayBuffer(cx, &dst->len, buffer);
@@ -1492,6 +1496,8 @@ ngx_qjs_string(ngx_engine_t *e, JSValueConst val, ngx_str_t *dst)
}
}

+string:
+
str = JS_ToCString(cx, val);
if (str == NULL) {
return NGX_ERROR;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Optimized ngx_qjs_string().

Anonymous User 196 October 08, 2024 07:06PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 240
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready