No more in operator, checking for undefined is much much faster

This commit is contained in:
Tom MacWright 2013-01-04 18:45:19 -05:00
parent bfc9d40f43
commit f3bde1fde3

View File

@ -89,30 +89,30 @@ tree.Filterset.prototype.addable = function(filter) {
switch (filter.op) {
case '=':
// if there is already foo= and we're adding foo=
if (key + '=' in this.filters) {
if (this.filters[key + '='] !== undefined) {
if (this.filters[key + '='].val.toString() != value) {
return false;
} else {
return null;
}
}
if (key + '!=' + value in this.filters) return false;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return false;
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return false;
if (key + '>=' in this.filters && this.filters[key + '>='].val > value) return false;
if (key + '<=' in this.filters && this.filters[key + '<='].val < value) return false;
if (this.filters[key + '!=' + value] !== undefined) return false;
if (this.filters[key + '>'] !== undefined && this.filters[key + '>'].val >= value) return false;
if (this.filters[key + '<'] !== undefined && this.filters[key + '<'].val <= value) return false;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val > value) return false;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val < value) return false;
return true;
case '=~':
return true;
case '!=':
if (key + '=' in this.filters) return (this.filters[key + '='].val == value) ? false : null;
if (key + '!=' + value in this.filters) return null;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return null;
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return null;
if (key + '>=' in this.filters && this.filters[key + '>='].val > value) return null;
if (key + '<=' in this.filters && this.filters[key + '<='].val < value) return null;
if (this.filters[key + '='] !== undefined) return (this.filters[key + '='].val == value) ? false : null;
if (this.filters[key + '!=' + value] !== undefined) return null;
if (this.filters[key + '>'] !== undefined && this.filters[key + '>'].val >= value) return null;
if (this.filters[key + '<'] !== undefined && this.filters[key + '<'].val <= value) return null;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val > value) return null;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val < value) return null;
return true;
case '>':
@ -123,34 +123,34 @@ tree.Filterset.prototype.addable = function(filter) {
return null;
}
}
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return false;
if (key + '<=' in this.filters && this.filters[key + '<='].val <= value) return false;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return null;
if (key + '>=' in this.filters && this.filters[key + '>='].val > value) return null;
if (this.filters[key + '<'] !== undefined && this.filters[key + '<'].val <= value) return false;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val <= value) return false;
if (this.filters[key + '>'] !== undefined && this.filters[key + '>'].val >= value) return null;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val > value) return null;
return true;
case '>=':
if (key + '=' in this.filters) return (this.filters[key + '='].val < value) ? false : null;
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return false;
if (key + '<=' in this.filters && this.filters[key + '<='].val < value) return false;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return null;
if (key + '>=' in this.filters && this.filters[key + '>='].val >= value) return null;
if (this.filters[key + '=' ] !== undefined) return (this.filters[key + '='].val < value) ? false : null;
if (this.filters[key + '<' ] !== undefined && this.filters[key + '<'].val <= value) return false;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val < value) return false;
if (this.filters[key + '>' ] !== undefined && this.filters[key + '>'].val >= value) return null;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val >= value) return null;
return true;
case '<':
if (key + '=' in this.filters) return (this.filters[key + '='].val >= value) ? false : null;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return false;
if (key + '>=' in this.filters && this.filters[key + '>='].val >= value) return false;
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return null;
if (key + '<=' in this.filters && this.filters[key + '<='].val < value) return null;
if (this.filters[key + '=' ] !== undefined) return (this.filters[key + '='].val >= value) ? false : null;
if (this.filters[key + '>' ] !== undefined && this.filters[key + '>'].val >= value) return false;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val >= value) return false;
if (this.filters[key + '<' ] !== undefined && this.filters[key + '<'].val <= value) return null;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val < value) return null;
return true;
case '<=':
if (key + '=' in this.filters) return (this.filters[key + '='].val > value) ? false : null;
if (key + '>' in this.filters && this.filters[key + '>'].val >= value) return false;
if (key + '>=' in this.filters && this.filters[key + '>='].val > value) return false;
if (key + '<' in this.filters && this.filters[key + '<'].val <= value) return null;
if (key + '<=' in this.filters && this.filters[key + '<='].val <= value) return null;
if (this.filters[key + '=' ] !== undefined) return (this.filters[key + '='].val > value) ? false : null;
if (this.filters[key + '>' ] !== undefined && this.filters[key + '>'].val >= value) return false;
if (this.filters[key + '>='] !== undefined && this.filters[key + '>='].val > value) return false;
if (this.filters[key + '<' ] !== undefined && this.filters[key + '<'].val <= value) return null;
if (this.filters[key + '<='] !== undefined && this.filters[key + '<='].val <= value) return null;
return true;
}
};
@ -165,11 +165,11 @@ tree.Filterset.prototype.conflict = function(filter) {
// if (a=b) && (a=c)
// if (a=b) && (a!=b)
// or (a!=b) && (a=b)
if ((filter.op === '=' && key + '=' in this.filters &&
if ((filter.op === '=' && this.filters[key + '='] !== undefined &&
value != this.filters[key + '='].val.toString()) ||
(filter.op === '!=' && key + '=' in this.filters &&
(filter.op === '!=' && this.filters[key + '='] !== undefined &&
value == this.filters[key + '='].val.toString()) ||
(filter.op === '=' && key + '!=' in this.filters &&
(filter.op === '=' && this.filters[key + '!='] !== undefined &&
value == this.filters[key + '!='].val.toString())) {
return filter.toString() + ' added to ' + this.toString() + ' produces an invalid filter';
}
@ -213,7 +213,7 @@ tree.Filterset.prototype.add = function(filter, env) {
delete this.filters[k];
}
}
if (key + '!=' + filter.val in this.filters) {
if (this.filters[key + '!=' + filter.val] !== undefined) {
delete this.filters[key + '!=' + filter.val];
filter.op = '>';
this.filters[key + '>'] = filter;
@ -236,7 +236,7 @@ tree.Filterset.prototype.add = function(filter, env) {
delete this.filters[m];
}
}
if (key + '!=' + filter.val in this.filters) {
if (this.filters[key + '!=' + filter.val] !== undefined) {
delete this.filters[key + '!=' + filter.val];
filter.op = '<';
this.filters[key + '<'] = filter;