mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Add maxPoolSize to limit array and object pools.
Former-commit-id: 677cdb053c7ef60274d71d9ecf4d6f866ef6a8eb
This commit is contained in:
3
build.js
3
build.js
@@ -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', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user