highlightFTSResults: return earlier if the regexp is empty

A default-constructed QRegExp is passed to ArticleView::showDefinition()
when a user navigates from an FTS-result page by clicking a link or
double-clicking a word. QRegExp().pattern() returns an empty string,
which is stored in the "regexp" query item of an URL. When this URL is
loaded, ArticleView::loadFinished() calls highlightFTSResults(), which
then calls closeSearch(), performs multiple string and regular
expression operations and early-returns because the regular expression
pattern is empty. Returning earlier skips useless work in this case.

An alternative optimization is not calling highlightFTSResults() at all
when the regular expression is empty, but that would skip the
closeSearch() call and keep the FTS search frame visible on a page with
an empty regexp.
This commit is contained in:
Igor Kushnir 2022-07-01 19:48:42 +03:00
parent c936d03fa0
commit 1e43bdf18c

View file

@ -2556,9 +2556,10 @@ void ArticleView::highlightFTSResults()
const QUrl & url = ui.definition->url(); const QUrl & url = ui.definition->url();
bool ignoreDiacritics = Qt4x5::Url::hasQueryItem( url, "ignore_diacritics" );
QString regString = Qt4x5::Url::queryItemValue( url, "regexp" ); QString regString = Qt4x5::Url::queryItemValue( url, "regexp" );
if( regString.isEmpty() )
return;
const bool ignoreDiacritics = Qt4x5::Url::hasQueryItem( url, "ignore_diacritics" );
if( ignoreDiacritics ) if( ignoreDiacritics )
regString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( regString ) ) ); regString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( regString ) ) );
else else