diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-05-11 17:15:25 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-12 11:45:53 +0200 |
commit | ed4c1b4e90aa5cb7ce6e904667bbdd6131ce7307 (patch) | |
tree | a7a754d595c503051e21b8d474eba21fd0c0d13d /src/corelib/io/qurlidna.cpp | |
parent | 565c2e8cf9b7ed59a49256e6576137c92f17d047 (diff) |
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/io/qurlidna.cpp')
-rw-r--r-- | src/corelib/io/qurlidna.cpp | 17 |
1 files 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; } |