mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
784 B
37 lines
784 B
9 years ago
|
var MapCache = require('./_MapCache'),
|
||
|
assocSet = require('./_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 object.
|
||
|
*/
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
module.exports = stackSet;
|