mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Optimize LoopStatus variable for v8 using class
This commit is contained in:
parent
73b9268e0c
commit
fe0d1a749c
@ -107,6 +107,13 @@ function resolveRenderer(handler) {
|
|||||||
return createDeferredRenderer(handler);
|
return createDeferredRenderer(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LoopStatus(getLength, isLast, isFirst, getIndex) {
|
||||||
|
this.getLength = getLength;
|
||||||
|
this.isLast = isLast;
|
||||||
|
this.isFirst = isFirst;
|
||||||
|
this.getIndex = getIndex;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* Internal helper method to prevent null/undefined from being written out
|
* Internal helper method to prevent null/undefined from being written out
|
||||||
@ -129,25 +136,26 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var len = array.length;
|
var len = array.length;
|
||||||
var loopStatus = {
|
var loopStatus = new LoopStatus(
|
||||||
getLength: function () {
|
function getLength() {
|
||||||
return len;
|
return len;
|
||||||
},
|
},
|
||||||
isLast: function () {
|
function isLast() {
|
||||||
return i === len - 1;
|
return i === len - 1;
|
||||||
},
|
},
|
||||||
isFirst: function () {
|
function isFirst() {
|
||||||
return i === 0;
|
return i === 0;
|
||||||
},
|
},
|
||||||
getIndex: function () {
|
function getIndex() {
|
||||||
return i;
|
return i;
|
||||||
}
|
});
|
||||||
};
|
|
||||||
for (; i < len; i++) {
|
for (; i < len; i++) {
|
||||||
var o = array[i];
|
var o = array[i];
|
||||||
callback(o, loopStatus);
|
callback(o, loopStatus);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper method to handle loops without a status variable
|
* Internal helper method to handle loops without a status variable
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user