Fix compilation on MSVC
MSVC apparently doesn't like the way the QString::Data pointers got initialized. Also fixed a few warnings about signed/unsigned conversions. Change-Id: I1267979af7601129e5483f8785d4982a1f2f8182 Reviewed-on: http://codereview.qt.nokia.com/1558 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
92c4b63ee1
commit
718153cfa0
@ -1051,7 +1051,11 @@ QString::QString(const QChar *unicode, int size)
|
|||||||
} else {
|
} else {
|
||||||
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data){ Q_REFCOUNT_INITIALIZER(1), size, size, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = size;
|
||||||
|
d->alloc = (uint) size;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
memcpy(d->data(), unicode, size * sizeof(QChar));
|
memcpy(d->data(), unicode, size * sizeof(QChar));
|
||||||
d->data()[size] = '\0';
|
d->data()[size] = '\0';
|
||||||
}
|
}
|
||||||
@ -1079,7 +1083,11 @@ QString::QString(const QChar *unicode)
|
|||||||
} else {
|
} else {
|
||||||
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data){ Q_REFCOUNT_INITIALIZER(1), size, size, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = size;
|
||||||
|
d->alloc = (uint) size;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
memcpy(d->data(), unicode, size * sizeof(QChar));
|
memcpy(d->data(), unicode, size * sizeof(QChar));
|
||||||
d->data()[size] = '\0';
|
d->data()[size] = '\0';
|
||||||
}
|
}
|
||||||
@ -1100,7 +1108,11 @@ QString::QString(int size, QChar ch)
|
|||||||
} else {
|
} else {
|
||||||
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data){ Q_REFCOUNT_INITIALIZER(1), size, size, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = size;
|
||||||
|
d->alloc = (uint) size;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
d->data()[size] = '\0';
|
d->data()[size] = '\0';
|
||||||
ushort *i = d->data() + size;
|
ushort *i = d->data() + size;
|
||||||
ushort *b = d->data();
|
ushort *b = d->data();
|
||||||
@ -1120,7 +1132,11 @@ QString::QString(int size, Qt::Initialization)
|
|||||||
{
|
{
|
||||||
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data){ Q_REFCOUNT_INITIALIZER(1), size, size, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = size;
|
||||||
|
d->alloc = (uint) size;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
d->data()[size] = '\0';
|
d->data()[size] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1138,7 +1154,11 @@ QString::QString(QChar ch)
|
|||||||
{
|
{
|
||||||
d = (Data *) qMalloc(sizeof(Data) + 2*sizeof(QChar));
|
d = (Data *) qMalloc(sizeof(Data) + 2*sizeof(QChar));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data) { Q_REFCOUNT_INITIALIZER(1), 1, 1, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = 1;
|
||||||
|
d->alloc = 1;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
d->data()[0] = ch.unicode();
|
d->data()[0] = ch.unicode();
|
||||||
d->data()[1] = '\0';
|
d->data()[1] = '\0';
|
||||||
}
|
}
|
||||||
@ -1313,7 +1333,11 @@ void QString::realloc(int alloc)
|
|||||||
if (d->ref != 1 || d->offset) {
|
if (d->ref != 1 || d->offset) {
|
||||||
Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + (alloc+1) * sizeof(QChar)));
|
Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + (alloc+1) * sizeof(QChar)));
|
||||||
Q_CHECK_PTR(x);
|
Q_CHECK_PTR(x);
|
||||||
*x = (Data){ Q_REFCOUNT_INITIALIZER(1), qMin(alloc, d->size), alloc, d->capacityReserved, { 0 } };
|
x->ref = 1;
|
||||||
|
x->size = qMin(alloc, d->size);
|
||||||
|
x->alloc = (uint) alloc;
|
||||||
|
x->capacityReserved = d->capacityReserved;
|
||||||
|
x->offset =0;
|
||||||
::memcpy(x->data(), d->data(), x->size * sizeof(QChar));
|
::memcpy(x->data(), d->data(), x->size * sizeof(QChar));
|
||||||
x->data()[x->size] = 0;
|
x->data()[x->size] = 0;
|
||||||
if (!d->ref.deref())
|
if (!d->ref.deref())
|
||||||
@ -3747,7 +3771,11 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size)
|
|||||||
size = qstrlen(str);
|
size = qstrlen(str);
|
||||||
d = static_cast<Data *>(qMalloc(sizeof(Data) + (size+1) * sizeof(QChar)));
|
d = static_cast<Data *>(qMalloc(sizeof(Data) + (size+1) * sizeof(QChar)));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
*d = (Data){ Q_REFCOUNT_INITIALIZER(1), size, size, false, { 0 } };
|
d->ref = 1;
|
||||||
|
d->size = size;
|
||||||
|
d->alloc = (uint) size;
|
||||||
|
d->capacityReserved = false;
|
||||||
|
d->offset = 0;
|
||||||
d->data()[size] = '\0';
|
d->data()[size] = '\0';
|
||||||
ushort *dst = d->data();
|
ushort *dst = d->data();
|
||||||
/* SIMD:
|
/* SIMD:
|
||||||
@ -7071,13 +7099,19 @@ bool QString::isRightToLeft() const
|
|||||||
*/
|
*/
|
||||||
QString QString::fromRawData(const QChar *unicode, int size)
|
QString QString::fromRawData(const QChar *unicode, int size)
|
||||||
{
|
{
|
||||||
Data *x = static_cast<Data *>(qMalloc(sizeof(Data)));
|
Data *x;
|
||||||
*x = (Data){ Q_REFCOUNT_INITIALIZER(1), size, 0, false, { 0 } };
|
if (!unicode) {
|
||||||
Q_CHECK_PTR(x);
|
x = const_cast<Data *>(&shared_null.str);
|
||||||
if (unicode) {
|
} else if (!size) {
|
||||||
x->offset = (const ushort *)unicode - (x->d + sizeof(qptrdiff)/sizeof(ushort));
|
x = const_cast<Data *>(&shared_empty.str);
|
||||||
} else {
|
} else {
|
||||||
size = 0;
|
x = static_cast<Data *>(qMalloc(sizeof(Data) + sizeof(ushort)));
|
||||||
|
Q_CHECK_PTR(x);
|
||||||
|
x->ref = 1;
|
||||||
|
x->size = size;
|
||||||
|
x->alloc = 0;
|
||||||
|
x->capacityReserved = false;
|
||||||
|
x->offset = (const ushort *)unicode - (x->d + sizeof(qptrdiff)/sizeof(ushort));
|
||||||
}
|
}
|
||||||
return QString(x, 0);
|
return QString(x, 0);
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ public:
|
|||||||
|
|
||||||
int capacity() const;
|
int capacity() const;
|
||||||
inline void reserve(int size);
|
inline void reserve(int size);
|
||||||
inline void squeeze() { if (d->size < d->alloc || d->ref != 1) realloc(); d->capacityReserved = false;}
|
inline void squeeze() { if (d->size < (int)d->alloc || d->ref != 1) realloc(); d->capacityReserved = false;}
|
||||||
|
|
||||||
inline const QChar *unicode() const;
|
inline const QChar *unicode() const;
|
||||||
inline QChar *data();
|
inline QChar *data();
|
||||||
@ -337,7 +337,7 @@ public:
|
|||||||
inline QString &prepend(const QLatin1String &s) { return insert(0, s); }
|
inline QString &prepend(const QLatin1String &s) { return insert(0, s); }
|
||||||
|
|
||||||
inline QString &operator+=(QChar c) {
|
inline QString &operator+=(QChar c) {
|
||||||
if (d->ref != 1 || d->size + 1 > d->alloc)
|
if (d->ref != 1 || d->size + 1 > (int)d->alloc)
|
||||||
realloc(grow(d->size + 1));
|
realloc(grow(d->size + 1));
|
||||||
d->data()[d->size++] = c.unicode();
|
d->data()[d->size++] = c.unicode();
|
||||||
d->data()[d->size] = '\0';
|
d->data()[d->size] = '\0';
|
||||||
@ -633,7 +633,7 @@ public:
|
|||||||
class Q_CORE_EXPORT QLatin1String
|
class Q_CORE_EXPORT QLatin1String
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline explicit QLatin1String(const char *s) : m_size(s ? strlen(s) : 0), m_data(s) {}
|
inline explicit QLatin1String(const char *s) : m_size(s ? (int)strlen(s) : 0), m_data(s) {}
|
||||||
|
|
||||||
inline const char *latin1() const { return m_data; }
|
inline const char *latin1() const { return m_data; }
|
||||||
inline int size() const { return m_size; }
|
inline int size() const { return m_size; }
|
||||||
@ -842,7 +842,7 @@ inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
|
|||||||
|
|
||||||
inline QString::QString() : d(const_cast<Data *>(&shared_null.str)) {}
|
inline QString::QString() : d(const_cast<Data *>(&shared_null.str)) {}
|
||||||
inline QString::~QString() { if (!d->ref.deref()) free(d); }
|
inline QString::~QString() { if (!d->ref.deref()) free(d); }
|
||||||
inline void QString::reserve(int asize) { if (d->ref != 1 || asize > d->alloc) realloc(asize); d->capacityReserved = true;}
|
inline void QString::reserve(int asize) { if (d->ref != 1 || asize > (int)d->alloc) realloc(asize); d->capacityReserved = true;}
|
||||||
inline QString &QString::setUtf16(const ushort *autf16, int asize)
|
inline QString &QString::setUtf16(const ushort *autf16, int asize)
|
||||||
{ return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); }
|
{ return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); }
|
||||||
inline QCharRef QString::operator[](int i)
|
inline QCharRef QString::operator[](int i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user