summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-10-25 16:31:43 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-10-26 11:47:58 +0300
commit9f60fd4ce9da281e64a026e32f34e834ae703cb9 (patch)
tree3d3244d80817168b93eb0325a91862554c1c2afd /src/libs
parent0b3be2f1b9c171ea11391e6018555a8efbb49a44 (diff)
Use static initialization for external-link regexp
Component::updateModelData() is invoked for every value change with any component, which can result in hundreds of thousands calls when there is a large number of components. We can avoid the repeated validity checks for the QRegularExpression object by initializing it as a static constant. When refiltering the same repository categories, which omits the metadata fetching part, there's a time reduction of some 10% from the start to displaying the component tree again measured by hand, which would match the results measured with callgrind. Also add similar handling to the related string literal. Change-Id: I90694f25e110b54a26ddd0fbc7f9319a6fb5314e Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/component.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index 36fadf451..5d21cd1da 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -1731,9 +1731,10 @@ void Component::updateModelData(const QString &key, const QString &data)
tooltipText += QLatin1String("<br>") + tr("There was an error loading the selected component. "
"This component cannot be installed.");
}
+ static const QRegularExpression externalLinkRegexp(QLatin1String("{external-link}='(.*?)'"));
+ static const QLatin1String externalLinkElement(QLatin1String("<a href=\"\\1\">\\1</a>"));
// replace {external-link}='' fields in component description with proper link tags
- tooltipText.replace(QRegularExpression(QLatin1String("{external-link}='(.*?)'")),
- QLatin1String("<a href=\"\\1\">\\1</a>"));
+ tooltipText.replace(externalLinkRegexp, externalLinkElement);
setData(tooltipText, Qt::ToolTipRole);
}