returning self.Set was not a good idea

This commit is contained in:
gorhill 2016-07-09 21:40:07 -04:00
parent 068860ef74
commit 7e4e69fd84
1 changed files with 36 additions and 39 deletions

View File

@ -62,49 +62,47 @@ vAPI.domFilterer = (function() {
/******************************************************************************/ /******************************************************************************/
var SSet = (function() { if ( typeof self.Set !== 'function' ) {
if ( typeof self.Set === 'function' ) { self.Set = function() {
return self.Set;
}
var Set = function() {
this._set = []; this._set = [];
this._i = 0; this._i = 0;
this.value = undefined; this.value = undefined;
}; };
Set.prototype.polyfill = true; self.Set.prototype = {
Set.prototype.clear = function() { polyfill: true,
clear: function() {
this._set = []; this._set = [];
}; },
Set.prototype.add = function(k) { add: function(k) {
if ( this._set.indexOf(k) === -1 ) { if ( this._set.indexOf(k) === -1 ) {
this._set.push(k); this._set.push(k);
} }
}; },
Set.prototype.delete = function(k) { delete: function(k) {
var pos = this._set.indexOf(k); var pos = this._set.indexOf(k);
if ( pos !== -1 ) { if ( pos !== -1 ) {
this._set.splice(pos, 1); this._set.splice(pos, 1);
return true; return true;
} }
return false; return false;
}; },
Set.prototype.has = function(k) { has: function(k) {
return this._set.indexOf(k) !== -1; return this._set.indexOf(k) !== -1;
}; },
Set.prototype.values = function() { values: function() {
this._i = 0; this._i = 0;
return this; return this;
}; },
Set.prototype.next = function() { next: function() {
this.value = this._set[this._i]; this.value = this._set[this._i];
this._i += 1; this._i += 1;
return this; return this;
}
}; };
Object.defineProperty(Set.prototype, 'size', { Object.defineProperty(self.Set.prototype, 'size', {
get: function() { return this._set.length; } get: function() { return this._set.length; }
}); });
return Set; }
})();
/******************************************************************************/ /******************************************************************************/
@ -125,11 +123,10 @@ var allExceptions = Object.create(null);
var allSelectors = Object.create(null); var allSelectors = Object.create(null);
// Complex selectors, due to their nature may need to be "de-committed". A // Complex selectors, due to their nature may need to be "de-committed". A
// Set() is used to implement this functionality. For browser with no // Set() is used to implement this functionality.
// support of Set(), uBO will skip committing complex selectors.
var complexSelectorsOldResultSet; var complexSelectorsOldResultSet;
var complexSelectorsCurrentResultSet = new SSet(); var complexSelectorsCurrentResultSet = new Set();
/******************************************************************************/ /******************************************************************************/
@ -311,7 +308,7 @@ var domFilterer = {
// Complex selectors: non-incremental. // Complex selectors: non-incremental.
complexSelectorsOldResultSet = complexSelectorsCurrentResultSet; complexSelectorsOldResultSet = complexSelectorsCurrentResultSet;
complexSelectorsCurrentResultSet = new SSet(); complexSelectorsCurrentResultSet = new Set();
// Stock job 3 = complex css selectors/hide // Stock job 3 = complex css selectors/hide
// The handling of these can be considered optional, since they are // The handling of these can be considered optional, since they are