[njs] Modules: removing extra copy while streaming in qjs.
noreply at nginx.com
noreply at nginx.com
Wed Aug 27 01:59:41 UTC 2025
details: https://github.com/nginx/njs/commit/6842e1b8f2cf73243afdcb88b27d08fdaa861ad6
branches: master
commit: 6842e1b8f2cf73243afdcb88b27d08fdaa861ad6
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed, 13 Aug 2025 23:19:46 -0700
description:
Modules: removing extra copy while streaming in qjs.
---
nginx/ngx_http_js_module.c | 12 +-----------
nginx/ngx_stream_js_module.c | 13 +------------
2 files changed, 2 insertions(+), 23 deletions(-)
diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c
index 402c7382..487c8115 100644
--- a/nginx/ngx_http_js_module.c
+++ b/nginx/ngx_http_js_module.c
@@ -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;
diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c
index a3a85662..a7446c49 100644
--- a/nginx/ngx_stream_js_module.c
+++ b/nginx/ngx_stream_js_module.c
@@ -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;
}
More information about the nginx-devel
mailing list