Utils: Replace Id ctor from char * with char(&)[]

... and move the strlen() call to the header, where it can be replaced
at compile time with a constant for true literals.

Change-Id: I1c4b2b1c87b68bc218a235c95c90e4c8fa8e7a21
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2024-07-25 17:46:27 +02:00
parent d87cc5a6f6
commit 10b52c7dba
2 changed files with 9 additions and 4 deletions

View File

@@ -124,13 +124,14 @@ static quintptr theId(const char *str, int n)
\QC process. \QC process.
*/ */
Id::Id(const char *name) Id::Id(const char *s, size_t len)
: m_id(theId(name, 0)) : m_id(theId(s, len))
{} {}
Id Id::generate() Id Id::generate()
{ {
return Id{QUuid::createUuid().toByteArray()}; const QByteArray ba = QUuid::createUuid().toByteArray();
return Id(theId(ba.data(), ba.size()));
} }
/*! /*!

View File

@@ -22,7 +22,10 @@ class QTCREATOR_UTILS_EXPORT Id
{ {
public: public:
Id() = default; Id() = default;
Id(const char *name); // Good to use.
template <int N>
Id(const char (&s)[N]) : Id(s, N - 1) {}
Id(const QLatin1String &) = delete; Id(const QLatin1String &) = delete;
static Id generate(); static Id generate();
@@ -62,6 +65,7 @@ public:
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Id &id); friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Id &id);
private: private:
Id(const char *s, size_t len);
explicit Id(quintptr uid) : m_id(uid) {} explicit Id(quintptr uid) : m_id(uid) {}
quintptr m_id = 0; quintptr m_id = 0;