diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2012-11-20 07:18:01 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2012-11-20 08:57:35 +0100 |
commit | 7c4e2b6c60eb311ab5ce2bf1cc05fd10caf06350 (patch) | |
tree | 50ebe5aa9ff3552ef07c73986945c889fef3e452 /src/plugins/coreplugin/id.cpp | |
parent | f31da9ac552bdad551babfebfeadd7d99250ac9d (diff) | |
download | qt-creator-7c4e2b6c60eb311ab5ce2bf1cc05fd10caf06350.tar.gz |
Id: Add QByteArray constructor
Distinguish from const char * one.
QString ctor is yet to be removed
Change-Id: I2da231036c6417353b0566d39666d918ad141c6d
Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src/plugins/coreplugin/id.cpp')
-rw-r--r-- | src/plugins/coreplugin/id.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/plugins/coreplugin/id.cpp b/src/plugins/coreplugin/id.cpp index aa98d4db01..cebc36830b 100644 --- a/src/plugins/coreplugin/id.cpp +++ b/src/plugins/coreplugin/id.cpp @@ -52,13 +52,13 @@ namespace Core { class StringHolder { public: - explicit StringHolder(const char *s) - : str(s) + StringHolder(const char *s, int length) + : n(length), str(s) { - n = strlen(s); - int m = n; + if (!n) + length = n = strlen(s); h = 0; - while (m--) { + while (length--) { h = (h << 4) + *s++; h ^= (h & 0xf0000000) >> 23; h &= 0x0fffffff; @@ -97,10 +97,10 @@ static int lastUid = 0; static QVector<QByteArray> stringFromId; static IdCache idFromString; -static int theId(const char *str) +static int theId(const char *str, int n = 0) { QTC_ASSERT(str && *str, return 0); - StringHolder sh(str); + StringHolder sh(str, n); int res = idFromString.value(sh, 0); if (res == 0) { if (lastUid == 0) @@ -113,8 +113,17 @@ static int theId(const char *str) return res; } +static int theId(const QByteArray &ba) +{ + return theId(ba.constData(), ba.size()); +} + Id::Id(const char *name) - : m_id(theId(name)) + : m_id(theId(name, 0)) +{} + +Id::Id(const QByteArray &name) + : m_id(theId(name)) {} Id::Id(const QString &name) |