From c5b8c07f7e42eee4f7a58782fc504b60c4f1533f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 1 Nov 2016 15:18:21 +0000 Subject: [PATCH] various cleanups Signed-off-by: Ivailo Monev --- src/core/tools/qstring.cpp | 43 ++++------------------------------- src/core/tools/qstring.h | 7 +++--- src/gui/dialogs/qfileinfogatherer.cpp | 6 ++--- 3 files changed, 10 insertions(+), 46 deletions(-) diff --git a/src/core/tools/qstring.cpp b/src/core/tools/qstring.cpp index fe464b25e..8ba4100c1 100644 --- a/src/core/tools/qstring.cpp +++ b/src/core/tools/qstring.cpp @@ -985,47 +985,12 @@ QString::QString(const QChar *unicode, int size) } /*! - \since 4.7 - - Constructs a string initialized with the characters of the QChar array - \a unicode, which must be terminated with a 0. - - QString makes a deep copy of the string data. The unicode data is copied as - is and the Byte Order Mark is preserved if present. -*/ -QString::QString(const QChar *unicode) -{ - if (!unicode) { - d = &shared_null; - d->ref.ref(); - } else { - int size = 0; - while (unicode[size] != 0) - ++size; - if (!size) { - d = &shared_empty; - d->ref.ref(); - } else { - d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar)); - Q_CHECK_PTR(d); - d->ref = 1; - d->alloc = d->size = size; - d->capacity = 0; - d->data = d->array; - memcpy(d->array, unicode, size * sizeof(QChar)); - d->array[size] = '\0'; - } - } -} - - -/*! Constructs a string of the given \a size with every character set to \a ch. \sa fill() */ -QString::QString(int size, QChar ch) +QString::QString(const int size, const QChar ch) { if (size <= 0) { d = &shared_empty; @@ -1054,7 +1019,7 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data)+size*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->alloc = d->size = size; @@ -1073,9 +1038,9 @@ QString::QString(int size, Qt::Initialization) /*! Constructs a string of size 1 containing the character \a ch. */ -QString::QString(QChar ch) +QString::QString(const QChar ch) { - void *buf = malloc(sizeof(Data) + sizeof(QChar)); + void *buf = ::malloc(sizeof(Data) + sizeof(QChar)); Q_CHECK_PTR(buf); d = reinterpret_cast(buf); d->ref = 1; diff --git a/src/core/tools/qstring.h b/src/core/tools/qstring.h index 3957e5c5d..250f20ae9 100644 --- a/src/core/tools/qstring.h +++ b/src/core/tools/qstring.h @@ -72,10 +72,9 @@ class Q_CORE_EXPORT QString { public: inline QString(); - QString(const QChar *unicode, int size); // Qt5: don't cap size < 0 - explicit QString(const QChar *unicode); // Qt5: merge with the above - QString(QChar c); - QString(int size, QChar c); + QString(const QChar *unicode, int size = -1); + QString(const QChar c); + QString(const int size, const QChar c); inline QString(const QLatin1String &latin1); inline QString(const QString &); inline ~QString(); diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index 83bef43d2..f0114d572 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -251,15 +251,15 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil #endif QFileInfoList infoList; if (files.isEmpty()) { - infoList << QFieInfo(QDir::rootPath()); + infoList << QFileInfo(QDir::rootPath()); } else { for (int i = 0; i < files.count(); ++i) infoList << QFileInfo(files.at(i)); } for (int i = infoList.count() - 1; i >= 0; --i) { - QString driveName = infoList.at(i); + QFileInfo driveName = infoList.at(i); QList > updatedFiles; - updatedFiles.append(QPair(driveName.absoluteFilePath(), infoList.at(i))); + updatedFiles.append(QPair(driveName.absoluteFilePath(), driveName)); emit updates(path, updatedFiles); } return; -- 2.11.0