From 1e43bdf18c2918e8dc391cd80cf923bb35ac87dc Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Fri, 1 Jul 2022 19:48:42 +0300 Subject: [PATCH] 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. --- articleview.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/articleview.cc b/articleview.cc index 898a7d1e..66074eb5 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2556,9 +2556,10 @@ void ArticleView::highlightFTSResults() const QUrl & url = ui.definition->url(); - bool ignoreDiacritics = Qt4x5::Url::hasQueryItem( url, "ignore_diacritics" ); - QString regString = Qt4x5::Url::queryItemValue( url, "regexp" ); + if( regString.isEmpty() ) + return; + const bool ignoreDiacritics = Qt4x5::Url::hasQueryItem( url, "ignore_diacritics" ); if( ignoreDiacritics ) regString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( regString ) ) ); else