Add maxPoolSize to limit array and object pools.

Former-commit-id: 677cdb053c7ef60274d71d9ecf4d6f866ef6a8eb
This commit is contained in:
John-David Dalton
2013-06-03 08:43:04 -07:00
parent 9b214d75df
commit 819f4d2151
2 changed files with 12 additions and 0 deletions

View File

@@ -3231,6 +3231,9 @@
if (isRemoved(source, 'getObject', 'releaseObject')) {
source = removeVar(source, 'objectPool');
}
if (isRemoved(source, 'releaseArray', 'releaseObject')) {
source = removeVar(source, 'maxPoolSize');
}
if (isRemoved(source, 'invert')) {
source = replaceVar(source, 'htmlUnescapes', "{'&amp;':'&','&lt;':'<','&gt;':'>','&quot;':'\"','&#x27;':\"'\"}");
}

View File

@@ -39,6 +39,9 @@
/** Used as the size when optimizations are enabled for large arrays */
var largeArraySize = 75;
/** Used as the max size of the `arrayPool` and `objectPool` */
var maxPoolSize = 10;
/** Used to match empty string literals in compiled template source */
var reEmptyStringLeading = /\b__p \+= '';/g,
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
@@ -196,6 +199,9 @@
* @param {Array} [array] The array to release.
*/
function releaseArray(array) {
if (arrayPool.length == maxPoolSize) {
arrayPool.length = maxPoolSize - 1;
}
array.length = 0;
arrayPool.push(array);
}
@@ -207,6 +213,9 @@
* @param {Object} [object] The object to release.
*/
function releaseObject(object) {
if (objectPool.length == maxPoolSize) {
objectPool.length = maxPoolSize - 1;
}
object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
objectPool.push(object);
}