mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
37 lines
832 B
JavaScript
37 lines
832 B
JavaScript
define(['./_MapCache', './_assocSet'], function(MapCache, assocSet) {
|
|
|
|
/** Used as the size to enable large array optimizations. */
|
|
var LARGE_ARRAY_SIZE = 200;
|
|
|
|
/**
|
|
* Sets the stack `key` to `value`.
|
|
*
|
|
* @private
|
|
* @name set
|
|
* @memberOf Stack
|
|
* @param {string} key The key of the value to set.
|
|
* @param {*} value The value to set.
|
|
* @returns {Object} Returns the stack cache instance.
|
|
*/
|
|
function stackSet(key, value) {
|
|
var data = this.__data__,
|
|
array = data.array;
|
|
|
|
if (array) {
|
|
if (array.length < (LARGE_ARRAY_SIZE - 1)) {
|
|
assocSet(array, key, value);
|
|
} else {
|
|
data.array = null;
|
|
data.map = new MapCache(array);
|
|
}
|
|
}
|
|
var map = data.map;
|
|
if (map) {
|
|
map.set(key, value);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
return stackSet;
|
|
});
|