[njs] Improved memory footprint of RegExp.prototype.split().

Dmitry Volyntsev xeioex at nginx.com
Wed Oct 4 20:55:02 UTC 2023


details:   https://hg.nginx.org/njs/rev/c0aad58cfadb
branches:  
changeset: 2215:c0aad58cfadb
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Oct 04 13:35:38 2023 -0700
description:
Improved memory footprint of RegExp.prototype.split().

diffstat:

 src/njs_regexp.c |  16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diffs (44 lines):

diff -r cf85d0f8640a -r c0aad58cfadb src/njs_regexp.c
--- a/src/njs_regexp.c	Tue Oct 03 18:09:06 2023 -0700
+++ b/src/njs_regexp.c	Wed Oct 04 13:35:38 2023 -0700
@@ -1773,6 +1773,10 @@ njs_regexp_prototype_symbol_split(njs_vm
         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
         }
 
         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
             }
 
             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;
     }
 


More information about the nginx-devel mailing list