From 914b3bc9859c39db7e1caa5c558a2496e4c1c967 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Sep 2023 10:42:28 -0700 Subject: [PATCH] QStorageInfo/Linux: don't copy the mount info's contents until the end All these where somewhat cheap to copy (QStrings and QByteArrays), but why copy multiple times at all? Just copy at the end. Pick-to: 6.6 Change-Id: I9d43e5b91eb142d6945cfffd1787497434632dd4 Reviewed-by: Ahmad Samir Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo_linux.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 5b034bf4c2..502cb322fb 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -139,17 +139,21 @@ void QStorageInfoPrivate::initRootPath() const QString oldRootPath = rootPath; rootPath.clear(); - for (auto &info : infos) { + const MountInfo *bestInfo = nullptr; + for (const MountInfo &info : infos) { // we try to find most suitable entry qsizetype mpSize = info.mountPoint.size(); if (isParentOf(info.mountPoint, oldRootPath) && maxLength < mpSize) { + bestInfo = &info; maxLength = mpSize; - rootPath = info.mountPoint; - device = info.device; - fileSystemType = info.fsType; - subvolume = info.fsRoot; } } + if (bestInfo) { + rootPath = bestInfo->mountPoint; + device = bestInfo->device; + fileSystemType = bestInfo->fsType; + subvolume = bestInfo->fsRoot; + } } QList QStorageInfoPrivate::mountedVolumes()