From a1ef4f1bdc699e8136c59d8c3cfd19a4b20ac035 Mon Sep 17 00:00:00 2001 From: Marsup Date: Thu, 25 Feb 2016 12:15:02 +0000 Subject: [PATCH] Performance improvement --- stringify.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stringify.js b/stringify.js index 124a452..cd18a9e 100644 --- a/stringify.js +++ b/stringify.js @@ -16,8 +16,14 @@ function serializer(replacer, cycleReplacer) { return function(key, value) { if (stack.length > 0) { var thisPos = stack.indexOf(this) - ~thisPos ? stack.splice(thisPos + 1) : stack.push(this) - ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key) + if (~thisPos) { + stack.length = thisPos + 1 + keys.length = thisPos + 1 + keys[thisPos] = key + } else { + stack.push(this) + keys.push(key) + } if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value) } else stack.push(value)