mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
Revert "get rid of QString::shared_empty member"
This reverts commit 93d76d14e7
.
This commit is contained in:
parent
93d76d14e7
commit
bbff940f49
2 changed files with 22 additions and 10 deletions
|
@ -576,6 +576,8 @@ static int findChar(const QChar *str, int len, QChar ch, int from,
|
||||||
|
|
||||||
QString::Data QString::shared_null = { QAtomicInt(1),
|
QString::Data QString::shared_null = { QAtomicInt(1),
|
||||||
0, 0, 0, shared_null.array, {0} };
|
0, 0, 0, shared_null.array, {0} };
|
||||||
|
QString::Data QString::shared_empty = { QAtomicInt(1),
|
||||||
|
0, 0, 0, shared_empty.array, {0} };
|
||||||
|
|
||||||
int QString::grow(int size)
|
int QString::grow(int size)
|
||||||
{
|
{
|
||||||
|
@ -821,9 +823,12 @@ int QString::toWCharArray(wchar_t *array) const
|
||||||
*/
|
*/
|
||||||
QString::QString(const QChar *unicode, int size)
|
QString::QString(const QChar *unicode, int size)
|
||||||
{
|
{
|
||||||
if (!unicode || size <= 0) {
|
if (!unicode) {
|
||||||
d = &shared_null;
|
d = &shared_null;
|
||||||
d->ref.ref();
|
d->ref.ref();
|
||||||
|
} else if (size <= 0) {
|
||||||
|
d = &shared_empty;
|
||||||
|
d->ref.ref();
|
||||||
} else {
|
} else {
|
||||||
d = static_cast<Data*>(::malloc(sizeof(Data)+size*sizeof(QChar)));
|
d = static_cast<Data*>(::malloc(sizeof(Data)+size*sizeof(QChar)));
|
||||||
Q_CHECK_PTR(d);
|
Q_CHECK_PTR(d);
|
||||||
|
@ -845,7 +850,7 @@ QString::QString(const QChar *unicode, int size)
|
||||||
QString::QString(const int size, const QChar ch)
|
QString::QString(const int size, const QChar ch)
|
||||||
{
|
{
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
d = &shared_null;
|
d = &shared_empty;
|
||||||
d->ref.ref();
|
d->ref.ref();
|
||||||
} else {
|
} else {
|
||||||
d = static_cast<Data*>(::malloc(sizeof(Data)+size*sizeof(QChar)));
|
d = static_cast<Data*>(::malloc(sizeof(Data)+size*sizeof(QChar)));
|
||||||
|
@ -956,8 +961,8 @@ QString::QString(const QChar ch)
|
||||||
|
|
||||||
void QString::freeData(Data *d)
|
void QString::freeData(Data *d)
|
||||||
{
|
{
|
||||||
if(d != &shared_null)
|
if(d != &shared_null && d != &shared_empty)
|
||||||
::free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -996,7 +1001,7 @@ void QString::resize(int size)
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
if (size == 0 && !d->capacity) {
|
if (size == 0 && !d->capacity) {
|
||||||
Data *x = &shared_null;
|
Data *x = &shared_empty;
|
||||||
x->ref.ref();
|
x->ref.ref();
|
||||||
if (!d->ref.deref())
|
if (!d->ref.deref())
|
||||||
QString::freeData(d);
|
QString::freeData(d);
|
||||||
|
@ -1287,7 +1292,7 @@ QString& QString::insert(int i, QChar ch)
|
||||||
*/
|
*/
|
||||||
QString &QString::append(const QString &str)
|
QString &QString::append(const QString &str)
|
||||||
{
|
{
|
||||||
if (str.d != &shared_null) {
|
if (str.d != &shared_null && str.d != &shared_empty) {
|
||||||
if (d->ref != 1 || d->size + str.d->size > d->alloc)
|
if (d->ref != 1 || d->size + str.d->size > d->alloc)
|
||||||
reallocData(grow(d->size + str.d->size));
|
reallocData(grow(d->size + str.d->size));
|
||||||
memcpy(d->data + d->size, str.d->data, str.d->size * sizeof(QChar));
|
memcpy(d->data + d->size, str.d->data, str.d->size * sizeof(QChar));
|
||||||
|
@ -3126,7 +3131,7 @@ QString QString::right(int n) const
|
||||||
|
|
||||||
QString QString::mid(int position, int n) const
|
QString QString::mid(int position, int n) const
|
||||||
{
|
{
|
||||||
if (d == &shared_null || position >= d->size)
|
if (d == &shared_null || d == &shared_empty || position >= d->size)
|
||||||
return QString();
|
return QString();
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = d->size - position;
|
n = d->size - position;
|
||||||
|
@ -3403,9 +3408,12 @@ QVector<uint> QString::toUcs4() const
|
||||||
QString::Data *QString::fromLatin1_helper(const char *str, int size)
|
QString::Data *QString::fromLatin1_helper(const char *str, int size)
|
||||||
{
|
{
|
||||||
Data *d;
|
Data *d;
|
||||||
if (!str || size == 0 || (!*str && size < 0)) {
|
if (!str) {
|
||||||
d = &shared_null;
|
d = &shared_null;
|
||||||
d->ref.ref();
|
d->ref.ref();
|
||||||
|
} else if (size == 0 || (!*str && size < 0)) {
|
||||||
|
d = &shared_empty;
|
||||||
|
d->ref.ref();
|
||||||
} else {
|
} else {
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
size = qstrlen(str);
|
size = qstrlen(str);
|
||||||
|
@ -3428,9 +3436,12 @@ QString::Data *QString::fromAscii_helper(const char *str, int size)
|
||||||
#ifndef QT_NO_TEXTCODEC
|
#ifndef QT_NO_TEXTCODEC
|
||||||
if (codecForCStrings) {
|
if (codecForCStrings) {
|
||||||
Data *d;
|
Data *d;
|
||||||
if (!str || size == 0 || (!*str && size < 0)) {
|
if (!str) {
|
||||||
d = &shared_null;
|
d = &shared_null;
|
||||||
d->ref.ref();
|
d->ref.ref();
|
||||||
|
} else if (size == 0 || (!*str && size < 0)) {
|
||||||
|
d = &shared_empty;
|
||||||
|
d->ref.ref();
|
||||||
} else {
|
} else {
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
size = qstrlen(str);
|
size = qstrlen(str);
|
||||||
|
@ -7692,7 +7703,7 @@ QStringRef QString::rightRef(int n) const
|
||||||
|
|
||||||
QStringRef QString::midRef(int position, int n) const
|
QStringRef QString::midRef(int position, int n) const
|
||||||
{
|
{
|
||||||
if (d == &shared_null || position >= d->size)
|
if (d == &shared_null || d == &shared_empty || position >= d->size)
|
||||||
return QStringRef();
|
return QStringRef();
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = d->size - position;
|
n = d->size - position;
|
||||||
|
|
|
@ -477,6 +477,7 @@ private:
|
||||||
ushort array[1];
|
ushort array[1];
|
||||||
};
|
};
|
||||||
static Data shared_null;
|
static Data shared_null;
|
||||||
|
static Data shared_empty;
|
||||||
Data *d;
|
Data *d;
|
||||||
QString(Data *dd, int /*dummy*/) : d(dd) {}
|
QString(Data *dd, int /*dummy*/) : d(dd) {}
|
||||||
#ifndef QT_NO_TEXTCODEC
|
#ifndef QT_NO_TEXTCODEC
|
||||||
|
|
Loading…
Add table
Reference in a new issue