diff --git a/src/plugins/coreplugin/id.cpp b/src/plugins/coreplugin/id.cpp index 61f61144852..db3d7409b2b 100644 --- a/src/plugins/coreplugin/id.cpp +++ b/src/plugins/coreplugin/id.cpp @@ -53,16 +53,9 @@ namespace Core { in a more typesafe and faster manner than a plain \c QString or \c QByteArray would provide. - An id is internally represented as a 32 bit integer (its \c UID) - and associated with a plain 7-bit-clean ASCII name used + An id is associated with a plain 7-bit-clean ASCII name used for display and persistency. - Each plugin that is distributed as part of \QC has a - private range of 10000 UIDs that are guaranteed to be unique. - - Third party plugins are advised to construct ids from their - string representation. - */ class StringHolder @@ -85,8 +78,8 @@ public: } } int n; - uint h; const char *str; + quintptr h; }; static bool operator==(const StringHolder &sh1, const StringHolder &sh2) @@ -98,10 +91,10 @@ static bool operator==(const StringHolder &sh1, const StringHolder &sh2) static uint qHash(const StringHolder &sh) { - return sh.h; + return QT_PREPEND_NAMESPACE(qHash)(sh.h, 0); } -struct IdCache : public QHash +struct IdCache : public QHash { #ifndef QTC_ALLOW_STATIC_LEAKS ~IdCache() @@ -113,13 +106,12 @@ struct IdCache : public QHash }; -static int firstUnusedId = Id::IdsPerPlugin * Id::ReservedPlugins; - -static QHash stringFromId; +static QHash stringFromId; static IdCache idFromString; -static int theId(const char *str, int n = 0) +static quintptr theId(const char *str, int n = 0) { + static quintptr firstUnusedId = 10 * 1000 * 1000; QTC_ASSERT(str && *str, return 0); StringHolder sh(str, n); int res = idFromString.value(sh, 0); @@ -132,26 +124,20 @@ static int theId(const char *str, int n = 0) return res; } -static int theId(const QByteArray &ba) +static quintptr theId(const QByteArray &ba) { return theId(ba.constData(), ba.size()); } /*! - \fn Core::Id::Id(int uid) + \fn Core::Id::Id(quintptr uid) + \internal Constructs an id given \a UID. The UID is an integer value that is unique within the running \QC process. - It is the callers responsibility to ensure the uniqueness of - the passed integer. The recommended approach is to use - \c{registerId()} with an value taken from the plugin's - private range. - - \sa registerId() - */ /*! @@ -333,7 +319,7 @@ bool Id::operator==(const char *name) const } // For debugging purposes -CORE_EXPORT const char *nameForId(int id) +CORE_EXPORT const char *nameForId(quintptr id) { return stringFromId.value(id).str; } diff --git a/src/plugins/coreplugin/id.h b/src/plugins/coreplugin/id.h index 29d7cb47a75..f2ad3476431 100644 --- a/src/plugins/coreplugin/id.h +++ b/src/plugins/coreplugin/id.h @@ -46,10 +46,8 @@ namespace Core { class CORE_EXPORT Id { public: - enum { IdsPerPlugin = 10000, ReservedPlugins = 1000 }; - Id() : m_id(0) {} - Id(const char *name); + Id(const char *name); // Good to use. Id withSuffix(int suffix) const; Id withSuffix(const char *suffix) const; @@ -68,8 +66,8 @@ public: bool operator<(Id id) const { return m_id < id.m_id; } bool operator>(Id id) const { return m_id > id.m_id; } bool alphabeticallyBefore(Id other) const; - int uniqueIdentifier() const { return m_id; } - static Id fromUniqueIdentifier(int uid) { return Id(uid); } + + quintptr uniqueIdentifier() const { return m_id; } // Avoid. static Id fromString(const QString &str); // FIXME: avoid. static Id fromName(const QByteArray &ba); // FIXME: avoid. static Id fromSetting(const QVariant &variant); // Good to use. @@ -81,14 +79,13 @@ public: private: // Intentionally unimplemented - Id(const QLatin1String &); - // Force explicit use of fromUniqueIdentifier(). - explicit Id(int uid) : m_id(uid) {} + Id(const QLatin1String &) = delete; + explicit Id(quintptr uid) : m_id(uid) {} - int m_id; + quintptr m_id; }; -inline uint qHash(Id id) { return id.uniqueIdentifier(); } +inline uint qHash(Id id) { return static_cast(id.uniqueIdentifier()); } } // namespace Core