From ed4c1b4e90aa5cb7ce6e904667bbdd6131ce7307 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 May 2020 17:15:25 +0200 Subject: [PATCH] Cache QUrl::idnWhiteList() absent user_idn_whitelist Instead of creating a QStringList from a static array anew for each call, cache the result in a static variable. If we have to pay for the overhead of implicitly-shared classes, we should at least reap the benefits, too. Use IILE to gain automatic thread-safety (thread-safe statics). Change-Id: Ib92dd9cb85f84e013f98ca81565cc392bb39e76b Reviewed-by: Lars Knoll --- src/corelib/io/qurlidna.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp index f5ba691d72..9ef12899f0 100644 --- a/src/corelib/io/qurlidna.cpp +++ b/src/corelib/io/qurlidna.cpp @@ -2605,13 +2605,16 @@ QStringList QUrl::idnWhitelist() { if (user_idn_whitelist) return *user_idn_whitelist; - QStringList list; - list.reserve(idn_whitelist_size); - unsigned int i = 0; - while (i < idn_whitelist_size) { - list << QLatin1String(idn_whitelist[i]); - ++i; - } + static const QStringList list = [] { + QStringList list; + list.reserve(idn_whitelist_size); + unsigned int i = 0; + while (i < idn_whitelist_size) { + list << QLatin1String(idn_whitelist[i]); + ++i; + } + return list; + }(); return list; }