changeset 2606:caf716d4e693

Modules: removing extra copy while streaming in qjs.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 13 Aug 2025 23:19:46 -0700
parents a9ec849a6c8c
children 362ef716eabc
files nginx/ngx_http_js_module.c nginx/ngx_stream_js_module.c
diffstat 2 files changed, 2 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/nginx/ngx_http_js_module.c	Tue Aug 19 17:16:22 2025 -0700
+++ b/nginx/ngx_http_js_module.c	Wed Aug 13 23:19:46 2025 -0700
@@ -7398,7 +7398,6 @@
     ngx_http_js_ctx_t *ctx, ngx_chain_t *in)
 {
     size_t             len;
-    u_char            *p;
     JSAtom             last_key;
     JSValue            arguments[3], last;
     ngx_int_t          rc;
@@ -7425,16 +7424,7 @@
         if (!ctx->done) {
             len = b->last - b->pos;
 
-            p = ngx_pnalloc(r->pool, len);
-            if (p == NULL) {
-                return NJS_ERROR;
-            }
-
-            if (len) {
-                ngx_memcpy(p, b->pos, len);
-            }
-
-            arguments[1] = ngx_qjs_prop(cx, jlcf->buffer_type, p, len);
+            arguments[1] = ngx_qjs_prop(cx, jlcf->buffer_type, b->pos, len);
             if (JS_IsException(arguments[1])) {
                 JS_FreeAtom(cx, last_key);
                 return NGX_ERROR;
--- a/nginx/ngx_stream_js_module.c	Tue Aug 19 17:16:22 2025 -0700
+++ b/nginx/ngx_stream_js_module.c	Wed Aug 13 23:19:46 2025 -0700
@@ -2638,7 +2638,6 @@
     ngx_stream_js_ev_t *event, ngx_uint_t from_upstream)
 {
     size_t             len;
-    u_char            *p;
     JSContext         *cx;
     ngx_int_t          rc;
     ngx_str_t          exception;
@@ -2658,17 +2657,7 @@
 
     len = b ? b->last - b->pos : 0;
 
-    p = ngx_pnalloc(c->pool, len);
-    if (p == NULL) {
-        (void) JS_ThrowOutOfMemory(cx);
-        goto error;
-    }
-
-    if (len) {
-        ngx_memcpy(p, b->pos, len);
-    }
-
-    argv[0] = ngx_qjs_prop(cx, event->data_type, p, len);
+    argv[0] = ngx_qjs_prop(cx, event->data_type, b ? b->pos : NULL, len);
     if (JS_IsException(argv[0])) {
         goto error;
     }