Don't use a QTextStream to write the trash info file

Using a QTextStream to write the file is probably around
50 times slower than simply creating the required string
here and writing it.

Change-Id: Ia848e4ad2688f098c671938d7ad9aaa4764a4158
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Lars Knoll 2020-04-28 12:50:20 +02:00
parent 42d2d70abe
commit a308df82ae

View File

@ -43,7 +43,6 @@
#include "qfilesystemengine_p.h"
#include "qfile.h"
#include "qstorageinfo.h"
#include "qtextstream.h"
#include <QtCore/qoperatingsystemversion.h>
#include <QtCore/private/qcore_unix_p.h>
@ -1393,14 +1392,12 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
return false;
}
QTextStream out(&infoFile);
#if QT_CONFIG(textcodec)
out.setCodec("UTF-8");
#endif
out << "[Trash Info]" << Qt::endl;
out << "Path=" << sourcePath << Qt::endl;
out << "DeletionDate="
<< QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-ddThh:mm:ss")) << Qt::endl;
QByteArray info =
"[Trash Info]\n"
"Path=" + sourcePath.toUtf8() + "\n"
"DeletionDate=" + QDateTime::currentDateTime().toString(QLatin1String("yyyy-MM-ddThh:mm:ss")).toUtf8()
+ "\n";
infoFile.write(info);
infoFile.close();
newLocation = QFileSystemEntry(targetPath);