mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +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')) {
|
if (isRemoved(source, 'getObject', 'releaseObject')) {
|
||||||
source = removeVar(source, 'objectPool');
|
source = removeVar(source, 'objectPool');
|
||||||
}
|
}
|
||||||
|
if (isRemoved(source, 'releaseArray', 'releaseObject')) {
|
||||||
|
source = removeVar(source, 'maxPoolSize');
|
||||||
|
}
|
||||||
if (isRemoved(source, 'invert')) {
|
if (isRemoved(source, 'invert')) {
|
||||||
source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}");
|
source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
/** Used as the size when optimizations are enabled for large arrays */
|
/** Used as the size when optimizations are enabled for large arrays */
|
||||||
var largeArraySize = 75;
|
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 */
|
/** Used to match empty string literals in compiled template source */
|
||||||
var reEmptyStringLeading = /\b__p \+= '';/g,
|
var reEmptyStringLeading = /\b__p \+= '';/g,
|
||||||
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
||||||
@@ -196,6 +199,9 @@
|
|||||||
* @param {Array} [array] The array to release.
|
* @param {Array} [array] The array to release.
|
||||||
*/
|
*/
|
||||||
function releaseArray(array) {
|
function releaseArray(array) {
|
||||||
|
if (arrayPool.length == maxPoolSize) {
|
||||||
|
arrayPool.length = maxPoolSize - 1;
|
||||||
|
}
|
||||||
array.length = 0;
|
array.length = 0;
|
||||||
arrayPool.push(array);
|
arrayPool.push(array);
|
||||||
}
|
}
|
||||||
@@ -207,6 +213,9 @@
|
|||||||
* @param {Object} [object] The object to release.
|
* @param {Object} [object] The object to release.
|
||||||
*/
|
*/
|
||||||
function releaseObject(object) {
|
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;
|
object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
|
||||||
objectPool.push(object);
|
objectPool.push(object);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user