mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Add Stack#size.
This commit is contained in:
28
lodash.js
28
lodash.js
@@ -1900,8 +1900,8 @@
|
||||
* @memberOf Hash
|
||||
*/
|
||||
function hashClear() {
|
||||
this.size = 0;
|
||||
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2004,8 +2004,8 @@
|
||||
* @memberOf ListCache
|
||||
*/
|
||||
function listCacheClear() {
|
||||
this.size = 0;
|
||||
this.__data__ = [];
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2258,7 +2258,8 @@
|
||||
* @param {Array} [entries] The key-value pairs to cache.
|
||||
*/
|
||||
function Stack(entries) {
|
||||
this.__data__ = new ListCache(entries);
|
||||
var data = this.__data__ = new ListCache(entries);
|
||||
this.size = data.size;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2270,6 +2271,7 @@
|
||||
*/
|
||||
function stackClear() {
|
||||
this.__data__ = new ListCache;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2282,7 +2284,11 @@
|
||||
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
||||
*/
|
||||
function stackDelete(key) {
|
||||
return this.__data__['delete'](key);
|
||||
var data = this.__data__,
|
||||
result = data['delete'](key);
|
||||
|
||||
this.size = data.size;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2322,16 +2328,18 @@
|
||||
* @returns {Object} Returns the stack cache instance.
|
||||
*/
|
||||
function stackSet(key, value) {
|
||||
var cache = this.__data__;
|
||||
if (cache instanceof ListCache) {
|
||||
var pairs = cache.__data__;
|
||||
var data = this.__data__;
|
||||
if (data instanceof ListCache) {
|
||||
var pairs = data.__data__;
|
||||
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
||||
pairs.push([key, value]);
|
||||
this.size = ++data.size;
|
||||
return this;
|
||||
}
|
||||
cache = this.__data__ = new MapCache(pairs);
|
||||
data = this.__data__ = new MapCache(pairs);
|
||||
}
|
||||
cache.set(key, value);
|
||||
data.set(key, value);
|
||||
this.size = data.size;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -10343,7 +10351,7 @@
|
||||
return memoized;
|
||||
}
|
||||
|
||||
// Assign cache to `_.memoize`.
|
||||
// Expose `MapCache`.
|
||||
memoize.Cache = MapCache;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user