]> git.kaiwu.me - njs.git/commitdiff
Improved memory footprint of RegExp.prototype.split().
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 4 Oct 2023 20:35:38 +0000 (13:35 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 4 Oct 2023 20:35:38 +0000 (13:35 -0700)
src/njs_regexp.c

index 47a32375d2ab1ff1d3b2caebbff8083543cbdf7f..b6c86dbac370fc7b60986b7f1375f685de3c8578 100644 (file)
@@ -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;
     }