From aa697e3e98b479f8e62d756512f5b6db427b7a84 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 4 Oct 2023 13:35:38 -0700 Subject: [PATCH] Improved memory footprint of RegExp.prototype.split(). --- src/njs_regexp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/njs_regexp.c b/src/njs_regexp.c index 47a32375..b6c86dba 100644 --- a/src/njs_regexp.c +++ b/src/njs_regexp.c @@ -1773,6 +1773,10 @@ njs_regexp_prototype_symbol_split(njs_vm_t *vm, njs_value_t *args, e = njs_min(e, length); if (e == p) { + if (njs_object_slots(&z)) { + njs_regexp_exec_result_free(vm, njs_array(&z)); + } + q = q + 1; continue; } @@ -1794,6 +1798,10 @@ njs_regexp_prototype_symbol_split(njs_vm_t *vm, njs_value_t *args, } if (array->length == limit) { + if (njs_object_slots(&z)) { + njs_regexp_exec_result_free(vm, njs_array(&z)); + } + goto done; } @@ -1818,10 +1826,18 @@ njs_regexp_prototype_symbol_split(njs_vm_t *vm, njs_value_t *args, } if (array->length == limit) { + if (njs_object_slots(&z)) { + njs_regexp_exec_result_free(vm, njs_array(&z)); + } + goto done; } } + if (njs_object_slots(&z)) { + njs_regexp_exec_result_free(vm, njs_array(&z)); + } + q = p; } -- 2.47.3