forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Orgad Shaneh
parent
f31da9ac55
commit
7c4e2b6c60
@@ -63,7 +63,7 @@ class CORE_EXPORT Feature : public Id
|
||||
{
|
||||
friend class FeatureSet;
|
||||
public:
|
||||
Feature(const char *name) : Id(name) {}
|
||||
Feature(const char *name) : Id(QByteArray(name)) {}
|
||||
explicit Feature(const QString &name) : Id(name) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ Context::Context(const char *id, int offset)
|
||||
|
||||
void Context::add(const char *id)
|
||||
{
|
||||
d.append(Id(id).uniqueIdentifier());
|
||||
d.append(Id(QByteArray(id)).uniqueIdentifier());
|
||||
}
|
||||
|
||||
bool Context::contains(const char *id) const
|
||||
{
|
||||
return d.contains(Id(id).uniqueIdentifier());
|
||||
return d.contains(Id(QByteArray(id)).uniqueIdentifier());
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -43,7 +43,8 @@ class CORE_EXPORT Id
|
||||
public:
|
||||
Id() : m_id(0) {}
|
||||
Id(const char *name);
|
||||
// FIXME: Replace with QByteArray
|
||||
explicit Id(const QByteArray &name);
|
||||
// FIXME: Remove
|
||||
explicit Id(const QString &name);
|
||||
QByteArray name() const;
|
||||
QString toString() const;
|
||||
|
||||
Reference in New Issue
Block a user