1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-22 10:22:51 +01:00

Minor code review

Use class fields to declare/initialize instance and static
properties.
This commit is contained in:
Raymond Hill 2024-09-21 12:41:57 -04:00
parent f84b3e4ce9
commit 1c97ca10fc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -53,6 +53,9 @@ To create a log of net requests
/******************************************************************************/ /******************************************************************************/
const NetFilteringResultCache = class { const NetFilteringResultCache = class {
shelfLife = 15000;
extensionOriginURL = vAPI.getURL('/');
constructor() { constructor() {
this.pruneTimer = vAPI.defer.create(( ) => { this.pruneTimer = vAPI.defer.create(( ) => {
this.prune(); this.prune();
@ -172,9 +175,6 @@ const NetFilteringResultCache = class {
} }
}; };
NetFilteringResultCache.prototype.shelfLife = 15000;
NetFilteringResultCache.prototype.extensionOriginURL = vAPI.getURL('/');
/******************************************************************************/ /******************************************************************************/
// Frame stores are used solely to associate a URL with a frame id. // Frame stores are used solely to associate a URL with a frame id.
@ -274,18 +274,16 @@ const FrameStore = class {
} }
static factory(frameURL, parentId = -1) { static factory(frameURL, parentId = -1) {
const entry = FrameStore.junkyard.pop(); const FS = FrameStore;
if ( entry === undefined ) { if ( FS.junkyard.length !== 0 ) {
return new FrameStore(frameURL, parentId); return FS.junkyard.pop().init(frameURL, parentId);
} }
return entry.init(frameURL, parentId); return new FS(frameURL, parentId);
} }
static junkyard = [];
static junkyardMax = 50;
}; };
// To mitigate memory churning
FrameStore.junkyard = [];
FrameStore.junkyardMax = 50;
/******************************************************************************/ /******************************************************************************/
const CountDetails = class { const CountDetails = class {
@ -314,18 +312,24 @@ const HostnameDetails = class {
this.hostname = hostname; this.hostname = hostname;
this.cname = vAPI.net.canonicalNameFromHostname(hostname); this.cname = vAPI.net.canonicalNameFromHostname(hostname);
this.counts.reset(); this.counts.reset();
return this;
} }
dispose() { dispose() {
this.hostname = ''; const HD = HostnameDetails;
if ( HostnameDetails.junkyard.length < HostnameDetails.junkyardMax ) { if ( HD.junkyard.length >= HD.junkyardMax ) { return; }
HostnameDetails.junkyard.push(this); HD.junkyard.push(this);
}
} }
static factory(hostname) {
const HD = HostnameDetails;
if ( HD.junkyard.length !== 0 ) {
return HD.junkyard.pop().init(hostname);
}
return new HD(hostname);
}
static junkyard = [];
static junkyardMax = 100;
}; };
HostnameDetails.junkyard = [];
HostnameDetails.junkyardMax = 100;
const HostnameDetailsMap = class extends Map { const HostnameDetailsMap = class extends Map {
reset() { reset() {
this.clear(); this.clear();
@ -623,7 +627,7 @@ const PageStore = class {
) { ) {
this.hostnameDetailsMap.set( this.hostnameDetailsMap.set(
this.tabHostname, this.tabHostname,
new HostnameDetails(this.tabHostname) HostnameDetails.factory(this.tabHostname)
); );
} }
return this.hostnameDetailsMap; return this.hostnameDetailsMap;
@ -701,7 +705,7 @@ const PageStore = class {
const hostname = journal[i+0]; const hostname = journal[i+0];
let hnDetails = this.hostnameDetailsMap.get(hostname); let hnDetails = this.hostnameDetailsMap.get(hostname);
if ( hnDetails === undefined ) { if ( hnDetails === undefined ) {
hnDetails = new HostnameDetails(hostname); hnDetails = HostnameDetails.factory(hostname);
this.hostnameDetailsMap.set(hostname, hnDetails); this.hostnameDetailsMap.set(hostname, hnDetails);
this.contentLastModified = now; this.contentLastModified = now;
} }