SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 50 JavaScript
2016-07-24 09:52:04 -07:00
define(['./_ListCache', './_Map', './_MapCache'], function(ListCache, Map, MapCache) {
2015-12-16 17:53:20 -08:00
/** 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.
2016-03-26 00:00:01 -07:00
* @returns {Object} Returns the stack cache instance.
2015-12-16 17:53:20 -08:00
*/
function stackSet(key, value) {
2016-09-17 22:24:52 -07:00
var data = this.__data__;
if (data instanceof ListCache) {
var pairs = data.__data__;
2016-07-24 09:52:04 -07:00
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
pairs.push([key, value]);
2016-09-17 22:24:52 -07:00
this.size = ++data.size;
2016-07-24 09:52:04 -07:00
return this;
}
2016-09-17 22:24:52 -07:00
data = this.__data__ = new MapCache(pairs);
2015-12-16 17:53:20 -08:00
}
2016-09-17 22:24:52 -07:00
data.set(key, value);
this.size = data.size;
2015-12-16 17:53:20 -08:00
return this;
}
return stackSet;
});