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.
This commit is contained in:
parent
84ae4f9a5e
commit
5dc12f9a6d
@ -172,6 +172,17 @@ class PDFFindController {
|
|||||||
this._firstPageCapability = createPromiseCapability();
|
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
|
* Helper for multi-term search that fills the `matchesWithLength` array
|
||||||
* and handles cases where one search term includes another search term (for
|
* and handles cases where one search term includes another search term (for
|
||||||
@ -307,7 +318,7 @@ class PDFFindController {
|
|||||||
|
|
||||||
_calculateMatch(pageIndex) {
|
_calculateMatch(pageIndex) {
|
||||||
let pageContent = this._pageContents[pageIndex];
|
let pageContent = this._pageContents[pageIndex];
|
||||||
let query = normalize(this._state.query);
|
let query = this._query;
|
||||||
const { caseSensitive, entireWord, phraseSearch, } = this._state;
|
const { caseSensitive, entireWord, phraseSearch, } = this._state;
|
||||||
|
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
@ -425,7 +436,7 @@ class PDFFindController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there's no query there's no point in searching.
|
// If there's no query there's no point in searching.
|
||||||
if (this._state.query === '') {
|
if (this._query === '') {
|
||||||
this._updateUIState(FindState.FOUND);
|
this._updateUIState(FindState.FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user