From 94df3f8d6bfb40c9339256a93e47a495caff152c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Sep 2023 10:45:41 -0700 Subject: [PATCH] QStorageInfo/Unix: check the mount point length before isParentOf() Execute the cheaper test first, so we loop over the entries more quickly. Pick-to: 6.6 Change-Id: I9d43e5b91eb142d6945cfffd178749a12c966739 Reviewed-by: Ahmad Samir Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo_linux.cpp | 2 +- src/corelib/io/qstorageinfo_unix.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 552567c63b..62f9ee5ac0 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -143,7 +143,7 @@ void QStorageInfoPrivate::initRootPath() for (const MountInfo &info : infos) { // we try to find most suitable entry qsizetype mpSize = info.mountPoint.size(); - if (isParentOf(info.mountPoint, oldRootPath) && maxLength < mpSize) { + if (maxLength < mpSize && isParentOf(info.mountPoint, oldRootPath)) { bestInfo = &info; maxLength = mpSize; } diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 3c80c31453..af65823b1d 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -449,7 +449,7 @@ void QStorageInfoPrivate::initRootPath() const QString mountDir = it.rootPath(); const QByteArray fsName = it.fileSystemType(); // we try to find most suitable entry - if (isParentOf(mountDir, oldRootPath) && maxLength < mountDir.size()) { + if (maxLength < mountDir.size() && isParentOf(mountDir, oldRootPath)) { maxLength = mountDir.size(); rootPath = mountDir; device = it.device();