diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-02-22 21:27:37 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-03-19 07:09:55 +0000 |
commit | 6ec1dc904d59bab3a0330ff2a6c26600a35c87a9 (patch) | |
tree | 14acfbccb73bc6f722492d86900da61338ea17cd /src/corelib/io/qsettings_p.h | |
parent | 03de9ff7eefd9e635d16867c231153363acfdf4b (diff) |
QSettings: port key processing to QAnyStringView
... in preparation for replacing the QString keys in the public API
with QAnyStringView ones.
This removes the "important optimization" that avoids a detach in the
common case where the input is the same as the output of
normalization. But that optimization is beside the point, because it
trades a memory allocation avoided in the library for O(N) allocations
inserted into user code for each call to QSettings::value(), the vast
majority of which are calls with string literals.
With the public interface ported to QAnyStringView in the follow-up
patch, we can then internally optimize memory allocations _in a central
place_ (e.g. by returning std::u16string or QVarLengthArray<QChar> from
normalizeKey() instead of QString). But first we need to get rid of all
the unwarranted allocations in user code.
Change-Id: I45fc83d972c552a220c9c29508001d3f172e1162
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/io/qsettings_p.h')
-rw-r--r-- | src/corelib/io/qsettings_p.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h index 1573a39d2a..ac82429146 100644 --- a/src/corelib/io/qsettings_p.h +++ b/src/corelib/io/qsettings_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -209,14 +209,14 @@ public: virtual bool isWritable() const = 0; virtual QString fileName() const = 0; - QVariant value(const QString &key, const QVariant *defaultValue) const; - QString actualKey(const QString &key) const; + QVariant value(QAnyStringView key, const QVariant *defaultValue) const; + QString actualKey(QAnyStringView key) const; void beginGroupOrArray(const QSettingsGroup &group); void setStatus(QSettings::Status status) const; void requestUpdate(); void update(); - static QString normalizedKey(const QString &key); + static QString normalizedKey(QAnyStringView key); static QSettingsPrivate *create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application); static QSettingsPrivate *create(const QString &fileName, QSettings::Format format); |