basic speed improvement - eats more memory

This commit is contained in:
Amish Shah
2015-12-06 20:53:23 +00:00
parent b59f2940e3
commit ff7adf1cf7
6 changed files with 62 additions and 33 deletions

View File

@@ -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;
}
};