From fe0d1a749ced07c08fcbdb73b5c93b1b03a2e253 Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Thu, 11 Aug 2016 17:30:54 -0600 Subject: [PATCH] Optimize LoopStatus variable for v8 using class --- runtime/helpers.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/runtime/helpers.js b/runtime/helpers.js index 510a25e54..e7a139496 100644 --- a/runtime/helpers.js +++ b/runtime/helpers.js @@ -107,6 +107,13 @@ function resolveRenderer(handler) { return createDeferredRenderer(handler); } +function LoopStatus(getLength, isLast, isFirst, getIndex) { + this.getLength = getLength; + this.isLast = isLast; + this.isFirst = isFirst; + this.getIndex = getIndex; +} + module.exports = { /** * Internal helper method to prevent null/undefined from being written out @@ -129,25 +136,26 @@ module.exports = { } var i = 0; var len = array.length; - var loopStatus = { - getLength: function () { + var loopStatus = new LoopStatus( + function getLength() { return len; }, - isLast: function () { + function isLast() { return i === len - 1; }, - isFirst: function () { + function isFirst() { return i === 0; }, - getIndex: function () { + function getIndex() { return i; - } - }; + }); + for (; i < len; i++) { var o = array[i]; callback(o, loopStatus); } }, + /** * Internal helper method to handle loops without a status variable * @private