mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-22 18:32:45 +01:00
Replace requestIdleCallback() with new vAPI.defer utility
Related commit:
- 91f9795023
This commit is contained in:
parent
3b14fd915a
commit
63d0f124ba
@ -81,17 +81,17 @@ vAPI.defer = {
|
||||
this.onraf(...args);
|
||||
}
|
||||
}
|
||||
onidle(delay, ...args) {
|
||||
onidle(delay, options, ...args) {
|
||||
if ( this.timer !== null ) { return; }
|
||||
const delayInMs = vAPI.defer.normalizeDelay(delay);
|
||||
if ( delayInMs !== 0 ) {
|
||||
this.type = 0;
|
||||
this.timer = vAPI.setTimeout(( ) => {
|
||||
this.timer = null;
|
||||
this.onric(...args);
|
||||
this.onric(options, ...args);
|
||||
}, delayInMs);
|
||||
} else {
|
||||
this.onric(...args);
|
||||
this.onric(options, ...args);
|
||||
}
|
||||
}
|
||||
off() {
|
||||
@ -119,13 +119,13 @@ vAPI.defer = {
|
||||
this.callback(...args);
|
||||
});
|
||||
}
|
||||
onric(...args) {
|
||||
onric(options, ...args) {
|
||||
if ( this.timer !== null ) { return; }
|
||||
this.type = 2;
|
||||
this.timer = self.requestIdleCallback(deadline => {
|
||||
this.timer = null;
|
||||
this.callback(deadline, ...args);
|
||||
});
|
||||
}, options);
|
||||
}
|
||||
ongoing() {
|
||||
return this.timer !== null;
|
||||
|
@ -26,7 +26,6 @@
|
||||
const StaticExtFilteringHostnameDB = class {
|
||||
constructor(nBits, selfie = undefined) {
|
||||
this.nBits = nBits;
|
||||
this.timer = undefined;
|
||||
this.strToIdMap = new Map();
|
||||
this.hostnameToSlotIdMap = new Map();
|
||||
this.regexToSlotIdMap = new Map();
|
||||
@ -39,6 +38,9 @@ const StaticExtFilteringHostnameDB = class {
|
||||
if ( selfie !== undefined ) {
|
||||
this.fromSelfie(selfie);
|
||||
}
|
||||
this.cleanupTimer = vAPI.defer.create(( ) => {
|
||||
this.strToIdMap.clear();
|
||||
});
|
||||
}
|
||||
|
||||
store(hn, bits, s) {
|
||||
@ -48,7 +50,7 @@ const StaticExtFilteringHostnameDB = class {
|
||||
iStr = this.strSlots.length;
|
||||
this.strSlots.push(s);
|
||||
this.strToIdMap.set(s, iStr);
|
||||
if ( this.timer === undefined ) {
|
||||
if ( this.cleanupTimer.ongoing() === false ) {
|
||||
this.collectGarbage(true);
|
||||
}
|
||||
}
|
||||
@ -85,22 +87,11 @@ const StaticExtFilteringHostnameDB = class {
|
||||
}
|
||||
|
||||
collectGarbage(later = false) {
|
||||
if ( later === false ) {
|
||||
if ( this.timer !== undefined ) {
|
||||
self.cancelIdleCallback(this.timer);
|
||||
this.timer = undefined;
|
||||
}
|
||||
this.strToIdMap.clear();
|
||||
return;
|
||||
if ( later ) {
|
||||
return this.cleanupTimer.onidle(5000, { timeout: 5000 });
|
||||
}
|
||||
if ( this.timer !== undefined ) { return; }
|
||||
this.timer = self.requestIdleCallback(
|
||||
( ) => {
|
||||
this.timer = undefined;
|
||||
this.strToIdMap.clear();
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
this.cleanupTimer.off();
|
||||
this.strToIdMap.clear();
|
||||
}
|
||||
|
||||
// modifiers = 0: all items
|
||||
|
Loading…
Reference in New Issue
Block a user