From 56c39838859a6c5b3cd15f2f676bbf304f112b3e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 12 Feb 2022 00:53:34 +0800 Subject: [PATCH 1/2] Improve `Path` constructor performance --- src/base/path.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/base/path.cpp b/src/base/path.cpp index 89e3d3b0e..8f72c97ba 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -29,6 +29,8 @@ #include "path.h" +#include + #include #include #include @@ -44,8 +46,20 @@ const Qt::CaseSensitivity CASE_SENSITIVITY = Qt::CaseSensitive; const int PATHLIST_TYPEID = qRegisterMetaType("PathList"); +namespace +{ + QString cleanPath(const QString &path) + { + const bool hasSeparator = std::any_of(path.cbegin(), path.cend(), [](const QChar c) + { + return (c == u'/') || (c == u'\\'); + }); + return hasSeparator ? QDir::cleanPath(path) : path; + } +} + Path::Path(const QString &pathStr) - : m_pathStr {QDir::cleanPath(pathStr)} + : m_pathStr {cleanPath(pathStr)} { } From 70eed10a34411c3ae730b6e9d11f7aa13f7eebe4 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 12 Feb 2022 01:28:08 +0800 Subject: [PATCH 2/2] Fix wrong size Fix up cf96e6c64266bf11ba9cf3dc7d2eaf7628c6d7a9. --- src/base/bittorrent/ltqbitarray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/ltqbitarray.cpp b/src/base/bittorrent/ltqbitarray.cpp index 7a2c109f8..270344df1 100644 --- a/src/base/bittorrent/ltqbitarray.cpp +++ b/src/base/bittorrent/ltqbitarray.cpp @@ -65,6 +65,6 @@ namespace BitTorrent::LT for (int i = 0; i < dataLength; ++i) tmp[i] = reverseByte(bitsData[i]); - return QBitArray::fromBits(tmp.data(), tmp.size()); + return QBitArray::fromBits(tmp.data(), bits.size()); } }