From 574a4e6263f685b974f1778928d26de3323a8414 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 25 Apr 2022 12:26:59 -0400 Subject: [PATCH] Cache extracted compiled filter blocks in reverse lookup code To avoid repeatedly extracting the blocks on subsequent lookups. --- src/js/reverselookup-worker.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/js/reverselookup-worker.js b/src/js/reverselookup-worker.js index 48ea97498..0a5386ad5 100644 --- a/src/js/reverselookup-worker.js +++ b/src/js/reverselookup-worker.js @@ -55,7 +55,10 @@ const fromNetFilter = function(details) { for ( const assetKey in listEntries ) { const entry = listEntries[assetKey]; if ( entry === undefined ) { continue; } - const content = extractBlocks(entry.content, 'NETWORK_FILTERS:GOOD'); + if ( entry.networkContent === undefined ) { + entry.networkContent = extractBlocks(entry.content, 'NETWORK_FILTERS:GOOD'); + } + const content = entry.networkContent; let pos = 0; for (;;) { pos = content.indexOf(compiledFilter, pos); @@ -157,14 +160,17 @@ const fromExtendedFilter = function(details) { for ( const assetKey in listEntries ) { const entry = listEntries[assetKey]; if ( entry === undefined ) { continue; } - const content = extractBlocks( - entry.content, - 'COSMETIC_FILTERS:SPECIFIC', - 'COSMETIC_FILTERS:GENERIC', - 'SCRIPTLET_FILTERS', - 'HTML_FILTERS', - 'HTTPHEADER_FILTERS' - ); + if ( entry.extendedContent === undefined ) { + entry.extendedContent = extractBlocks( + entry.content, + 'COSMETIC_FILTERS:SPECIFIC', + 'COSMETIC_FILTERS:GENERIC', + 'SCRIPTLET_FILTERS', + 'HTML_FILTERS', + 'HTTPHEADER_FILTERS' + ); + } + const content = entry.extendedContent; let found; let pos = 0; while ( (pos = content.indexOf(needle, pos)) !== -1 ) {