diff --git a/src/libs/utils/id.cpp b/src/libs/utils/id.cpp index b40e97136b9..14e82b38279 100644 --- a/src/libs/utils/id.cpp +++ b/src/libs/utils/id.cpp @@ -137,10 +137,17 @@ Id Id::generate() Returns an internal representation of the id. */ -QByteArray Id::name() const +QByteArrayView Id::name() const { QReadLocker lock(&s_cacheMutex); - return stringFromId.value(m_id).str; + StringHolder holder = stringFromId.value(m_id); + return QByteArrayView(holder.str, holder.n); +} + +/*! \internal */ +QByteArray Id::toByteArray() const +{ + return name().toByteArray(); } /*! @@ -155,8 +162,7 @@ QByteArray Id::name() const QString Id::toString() const { - QReadLocker lock(&s_cacheMutex); - return QString::fromUtf8(stringFromId.value(m_id).str); + return QString::fromUtf8(name()); } /*! \internal */ @@ -335,14 +341,14 @@ bool Id::alphabeticallyBefore(Id other) const QString Id::suffixAfter(Id baseId) const { - const QByteArray b = baseId.name(); - const QByteArray n = name(); + const QByteArrayView b = baseId.name(); + const QByteArrayView n = name(); return n.startsWith(b) ? QString::fromUtf8(n.mid(b.size())) : QString(); } QDataStream &operator<<(QDataStream &ds, Id id) { - return ds << id.name(); + return ds << id.name().toByteArray(); } QDataStream &operator>>(QDataStream &ds, Id &id) diff --git a/src/libs/utils/id.h b/src/libs/utils/id.h index e8a150a49fa..9e80af45352 100644 --- a/src/libs/utils/id.h +++ b/src/libs/utils/id.h @@ -34,7 +34,8 @@ public: Id withSuffix(const QStringView suffix) const; Id withPrefix(const char *prefix) const; - QByteArray name() const; + QByteArrayView name() const; + QByteArray toByteArray() const; // Avoid QString toString() const; // Avoid. Key toKey() const; // FIXME: Replace uses with .name() after Store/key transition. QVariant toSetting() const; // Good to use. diff --git a/src/libs/utils/storekey.h b/src/libs/utils/storekey.h index 68b433d05a6..faffd20c4fe 100644 --- a/src/libs/utils/storekey.h +++ b/src/libs/utils/storekey.h @@ -19,6 +19,7 @@ public: Key(Key &&) = default; Key(const QByteArray &key) : data(key) {} + Key(const QByteArrayView key) : data(key.toByteArray()) {} template Key(const char (&key)[N]) : data(key) {} diff --git a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp index 914a750e09a..1881a559828 100644 --- a/src/plugins/coreplugin/actionmanager/actioncontainer.cpp +++ b/src/plugins/coreplugin/actionmanager/actioncontainer.cpp @@ -597,7 +597,7 @@ TouchBarActionContainer::TouchBarActionContainer(Id id, const QIcon &icon, const QString &text) : ActionContainerPrivate(id, actionManagerPrivate) - , m_touchBar(std::make_unique(id.withPrefix(ID_PREFIX).name(), icon, text)) + , m_touchBar(std::make_unique(id.withPrefix(ID_PREFIX).toByteArray(), icon, text)) { } @@ -623,7 +623,7 @@ QAction *TouchBarActionContainer::actionForItem(QObject *item) const void TouchBarActionContainer::insertAction(QAction *before, Command *command) { m_touchBar->insertAction(before, - command->id().withPrefix(ID_PREFIX).name(), + command->id().withPrefix(ID_PREFIX).toByteArray(), command->touchBarAction()); } diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index e0b60d4c550..87cc4d043fa 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -158,7 +158,7 @@ Environment ExternalTool::baseEnvironment() const { if (m_baseEnvironmentProviderId.isValid()) { const std::optional provider = EnvironmentProvider::provider( - m_baseEnvironmentProviderId.name()); + m_baseEnvironmentProviderId.toByteArray()); if (provider && provider->environment) return provider->environment(); } diff --git a/src/plugins/macros/macroevent.cpp b/src/plugins/macros/macroevent.cpp index f82e372131b..d4d058415c8 100644 --- a/src/plugins/macros/macroevent.cpp +++ b/src/plugins/macros/macroevent.cpp @@ -52,7 +52,7 @@ void MacroEvent::load(QDataStream &stream) void MacroEvent::save(QDataStream &stream) const { - stream << m_id.name(); + stream << m_id.toByteArray(); stream << int(m_values.count()); for (auto i = m_values.cbegin(), end = m_values.cend(); i != end; ++i) stream << i.key() << i.value();