mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
basic speed improvement - eats more memory
This commit is contained in:
@@ -14,12 +14,23 @@ var Cache = (function (_Array) {
|
||||
|
||||
_Array.call(this);
|
||||
this.discrim = discrim || "id";
|
||||
this.discrimCache = [];
|
||||
this.highPerformance = false;
|
||||
}
|
||||
|
||||
Cache.prototype.setHighPerformance = function setHighPerformance() {
|
||||
this.highPerformance = true;
|
||||
};
|
||||
|
||||
Cache.prototype.setNormalPerformance = function setNormalPerformance() {
|
||||
this.discrimCache = [];
|
||||
this.highPerformance = false;
|
||||
};
|
||||
|
||||
Cache.prototype.get = function get(key, value) {
|
||||
var found = null;
|
||||
this.forEach(function (val, index, array) {
|
||||
if (val.hasOwnProperty(key) && val[key] == value) {
|
||||
if (val[key] == value) {
|
||||
found = val;
|
||||
return;
|
||||
}
|
||||
@@ -44,32 +55,15 @@ var Cache = (function (_Array) {
|
||||
|
||||
Cache.prototype.add = function add(data) {
|
||||
var exit = false;
|
||||
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var item = _ref;
|
||||
|
||||
if (item[this.discrim] === data[this.discrim]) {
|
||||
exit = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit = ~this.discrimCache.indexOf(data[this.discrim]);
|
||||
if (exit) {
|
||||
return exit;
|
||||
return data;
|
||||
} else {
|
||||
if (this.limit && this.length >= this.limit) {
|
||||
this.splice(0, 1);
|
||||
}
|
||||
this.push(data);
|
||||
this.discrimCache.push(data[this.discrim]);
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user