From 022f93280646eb0fc4c9670ff2b08a8232ceec31 Mon Sep 17 00:00:00 2001 From: Stefan Fehrenbach Date: Sun, 19 Nov 2017 19:22:47 +0000 Subject: [PATCH] Reuse the array returned by match (#89) Instead of basically making a copy and letting the original go out of scope immediately after. This makes a surprisingly large performance difference in Chrome, not so much in Firefox. --- src/Data/String/Regex.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js index 1d7e407..2e3ac3b 100644 --- a/src/Data/String/Regex.js +++ b/src/Data/String/Regex.js @@ -49,11 +49,10 @@ exports._match = function (just) { if (m == null) { return nothing; } else { - var list = []; for (var i = 0; i < m.length; i++) { - list.push(m[i] == null ? nothing : just(m[i])); + m[i] = m[i] == null ? nothing : just(m[i]); } - return just(list); + return just(m); } }; };