From 5dc12f9a6de58ae0db4c24fb3dc8723ae12131e5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 26 Oct 2018 20:53:42 +0200 Subject: [PATCH] Only normalize the search query once, in `PDFFindController, for every page being searched For a short document, such as e.g. the `tracemonkey` file, this repeated normalization won't matter much, but for documents with a couple of thousand pages it seems completely unnecessary (and wasteful) to keep repeating the normalization whenever for every single page. --- web/pdf_find_controller.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 1db2e32bd..a7b2eb0a6 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -172,6 +172,17 @@ class PDFFindController { this._firstPageCapability = createPromiseCapability(); } + /** + * @return {string} The (current) normalized search query. + */ + get _query() { + if (this._state.query !== this._rawQuery) { + this._rawQuery = this._state.query; + this._normalizedQuery = normalize(this._state.query); + } + return this._normalizedQuery; + } + /** * Helper for multi-term search that fills the `matchesWithLength` array * and handles cases where one search term includes another search term (for @@ -307,7 +318,7 @@ class PDFFindController { _calculateMatch(pageIndex) { let pageContent = this._pageContents[pageIndex]; - let query = normalize(this._state.query); + let query = this._query; const { caseSensitive, entireWord, phraseSearch, } = this._state; if (query.length === 0) { @@ -425,7 +436,7 @@ class PDFFindController { } // If there's no query there's no point in searching. - if (this._state.query === '') { + if (this._query === '') { this._updateUIState(FindState.FOUND); return; }