mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-03 01:29:39 +02:00
as per #2612, use native Set() in content scripts
This commit is contained in:
parent
8f42232105
commit
139d97179f
@ -72,114 +72,6 @@ if ( vAPI.sessionId ) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Support minimally working Set() for legacy Chromium.
|
|
||||||
|
|
||||||
if ( self.Set instanceof Function ) {
|
|
||||||
self.createSet = function() {
|
|
||||||
return new Set();
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
self.createSet = (function() {
|
|
||||||
//console.log('Polyfilling for ES6-like Set().');
|
|
||||||
var PrimitiveSet = function() {
|
|
||||||
this.clear();
|
|
||||||
};
|
|
||||||
PrimitiveSet.prototype = {
|
|
||||||
add: function(k) {
|
|
||||||
if ( this._set[k] === undefined ) {
|
|
||||||
this._set[k] = true;
|
|
||||||
this.size += 1;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
clear: function() {
|
|
||||||
this._set = Object.create(null);
|
|
||||||
this.size = 0;
|
|
||||||
this._values = undefined;
|
|
||||||
this._i = undefined;
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = true;
|
|
||||||
},
|
|
||||||
delete: function(k) {
|
|
||||||
if ( this._set[k] === undefined ) { return false; }
|
|
||||||
delete this._set[k];
|
|
||||||
this.size -= 1;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
has: function(k) {
|
|
||||||
return this._set[k] !== undefined;
|
|
||||||
},
|
|
||||||
next: function() {
|
|
||||||
if ( this._i < this.size ) {
|
|
||||||
this.value = this._values[this._i++];
|
|
||||||
} else {
|
|
||||||
this._values = undefined;
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = true;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
polyfill: true,
|
|
||||||
values: function() {
|
|
||||||
this._values = Object.keys(this._set);
|
|
||||||
this._i = 0;
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var ReferenceSet = function() {
|
|
||||||
this.clear();
|
|
||||||
};
|
|
||||||
ReferenceSet.prototype = {
|
|
||||||
add: function(k) {
|
|
||||||
if ( this._set.indexOf(k) === -1 ) {
|
|
||||||
this._set.push(k);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
clear: function() {
|
|
||||||
this._set = [];
|
|
||||||
this._i = 0;
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = true;
|
|
||||||
},
|
|
||||||
delete: function(k) {
|
|
||||||
var pos = this._set.indexOf(k);
|
|
||||||
if ( pos === -1 ) { return false; }
|
|
||||||
this._set.splice(pos, 1);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
has: function(k) {
|
|
||||||
return this._set.indexOf(k) !== -1;
|
|
||||||
},
|
|
||||||
next: function() {
|
|
||||||
if ( this._i === this._set.length ) {
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = true;
|
|
||||||
} else {
|
|
||||||
this.value = this._set[this._i];
|
|
||||||
this._i += 1;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
polyfill: true,
|
|
||||||
values: function() {
|
|
||||||
this._i = 0;
|
|
||||||
this.done = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Object.defineProperty(ReferenceSet.prototype, 'size', {
|
|
||||||
get: function() { return this._set.length; }
|
|
||||||
});
|
|
||||||
return function(type) {
|
|
||||||
return type === 'object' ? new ReferenceSet() : new PrimitiveSet();
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var referenceCounter = 0;
|
var referenceCounter = 0;
|
||||||
|
|
||||||
vAPI.lock = function() {
|
vAPI.lock = function() {
|
||||||
|
@ -54,46 +54,6 @@ var vAPI = self.vAPI;
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Support minimally working Set() for legacy Firefox: iterator for legacy
|
|
||||||
// Set() does not work like the one for standard ES6 Set().
|
|
||||||
|
|
||||||
if ( self.Set.prototype.iterator instanceof Function === false ) {
|
|
||||||
self.createSet = function() {
|
|
||||||
return new Set();
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
self.createSet = (function() {
|
|
||||||
//console.log('Patching non-ES6 Set() to be more ES6-like.');
|
|
||||||
var values = function() {
|
|
||||||
this._valueIter = this.prototype.values();
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = false;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
var next = function() {
|
|
||||||
try {
|
|
||||||
this.value = this._valueIter.next();
|
|
||||||
} catch (ex) {
|
|
||||||
this._valueIter = undefined;
|
|
||||||
this.value = undefined;
|
|
||||||
this.done = true;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
return function() {
|
|
||||||
var r = new Set();
|
|
||||||
r._valueIter = undefined;
|
|
||||||
r.value = undefined;
|
|
||||||
r.done = false;
|
|
||||||
r.values = values.bind(r);
|
|
||||||
r.next = next.bind(r);
|
|
||||||
return r;
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var referenceCounter = 0;
|
var referenceCounter = 0;
|
||||||
|
|
||||||
vAPI.lock = function() {
|
vAPI.lock = function() {
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global createSet */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -139,15 +137,15 @@ vAPI.domFilterer = (function() {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var allExceptions = createSet(),
|
var allExceptions = new Set(),
|
||||||
allSelectors = createSet(),
|
allSelectors = new Set(),
|
||||||
stagedNodes = [];
|
stagedNodes = [];
|
||||||
|
|
||||||
// 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.
|
// Set() is used to implement this functionality.
|
||||||
|
|
||||||
var complexSelectorsOldResultSet,
|
var complexSelectorsOldResultSet,
|
||||||
complexSelectorsCurrentResultSet = createSet('object');
|
complexSelectorsCurrentResultSet = new Set();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -597,7 +595,7 @@ var domFilterer = {
|
|||||||
this.commitTimer.clear();
|
this.commitTimer.clear();
|
||||||
|
|
||||||
var beforeHiddenNodeCount = this.hiddenNodeCount,
|
var beforeHiddenNodeCount = this.hiddenNodeCount,
|
||||||
styleText = '', i;
|
styleText = '';
|
||||||
|
|
||||||
// CSS rules/hide
|
// CSS rules/hide
|
||||||
if ( this.newHideSelectorBuffer.length ) {
|
if ( this.newHideSelectorBuffer.length ) {
|
||||||
@ -615,7 +613,7 @@ var domFilterer = {
|
|||||||
|
|
||||||
// Simple css selectors/hide
|
// Simple css selectors/hide
|
||||||
if ( this.simpleHideSelectors.entries.length ) {
|
if ( this.simpleHideSelectors.entries.length ) {
|
||||||
i = stagedNodes.length;
|
var i = stagedNodes.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
this.simpleHideSelectors.forEachNode(hideNode, stagedNodes[i], cssNotHiddenId);
|
this.simpleHideSelectors.forEachNode(hideNode, stagedNodes[i], cssNotHiddenId);
|
||||||
}
|
}
|
||||||
@ -624,7 +622,7 @@ var domFilterer = {
|
|||||||
|
|
||||||
// Complex selectors: non-incremental.
|
// Complex selectors: non-incremental.
|
||||||
complexSelectorsOldResultSet = complexSelectorsCurrentResultSet;
|
complexSelectorsOldResultSet = complexSelectorsCurrentResultSet;
|
||||||
complexSelectorsCurrentResultSet = createSet('object');
|
complexSelectorsCurrentResultSet = new Set();
|
||||||
|
|
||||||
// Complex css selectors/hide
|
// 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
|
||||||
@ -658,14 +656,10 @@ var domFilterer = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Un-hide nodes previously hidden.
|
// Un-hide nodes previously hidden.
|
||||||
i = complexSelectorsOldResultSet.size;
|
for ( var node of complexSelectorsOldResultSet ) {
|
||||||
if ( i !== 0 ) {
|
this.unhideNode(node);
|
||||||
var iter = complexSelectorsOldResultSet.values();
|
|
||||||
while ( i-- ) {
|
|
||||||
this.unhideNode(iter.next().value);
|
|
||||||
}
|
}
|
||||||
complexSelectorsOldResultSet.clear();
|
complexSelectorsOldResultSet.clear();
|
||||||
}
|
|
||||||
|
|
||||||
// If DOM nodes have been affected, lazily notify core process.
|
// If DOM nodes have been affected, lazily notify core process.
|
||||||
if (
|
if (
|
||||||
@ -1303,7 +1297,7 @@ vAPI.domSurveyor = (function() {
|
|||||||
cosmeticSurveyingMissCount = 0,
|
cosmeticSurveyingMissCount = 0,
|
||||||
highGenerics = null,
|
highGenerics = null,
|
||||||
lowGenericSelectors = [],
|
lowGenericSelectors = [],
|
||||||
queriedSelectors = createSet(),
|
queriedSelectors = new Set(),
|
||||||
surveyCost = 0;
|
surveyCost = 0;
|
||||||
|
|
||||||
// Handle main process' response.
|
// Handle main process' response.
|
||||||
|
Loading…
Reference in New Issue
Block a user