]> git.kaiwu.me - njs.git/commitdiff
Modules: removing extra copy while streaming in qjs.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 14 Aug 2025 06:19:46 +0000 (23:19 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 27 Aug 2025 01:36:30 +0000 (18:36 -0700)
nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c

index 402c7382b3bcb6f55798895084f54b4feb261dd9..487c8115dcca2fe5b7ba9ba7047eb315abe5a2af 100644 (file)
@@ -7398,7 +7398,6 @@ ngx_http_qjs_body_filter(ngx_http_request_t *r, ngx_http_js_loc_conf_t *jlcf,
     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 @@ ngx_http_qjs_body_filter(ngx_http_request_t *r, ngx_http_js_loc_conf_t *jlcf,
         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;
index a3a8566235ba83f9544ff5f7be165f80d150f187..a7446c49b7d684ec3b153e7b3e1e125a2523ead3 100644 (file)
@@ -2638,7 +2638,6 @@ ngx_stream_qjs_run_event(ngx_stream_session_t *s, ngx_stream_js_ctx_t *ctx,
     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 @@ ngx_stream_qjs_run_event(ngx_stream_session_t *s, ngx_stream_js_ctx_t *ctx,
 
     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;
     }