From f44c47a3015604fa50f95db1239b0798ed870222 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Thu, 14 Dec 2023 23:27:31 +0200 Subject: QFileSystemEntry: store special index, -2, in a contexpr variable It is used to indicate resolveFilePaht() should be called, making it a named variable makes the intention clearer. Change-Id: Ibf1c88b9dacc59775afdf76bab3a8c86a52d5c72 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystementry.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/corelib/io/qfilesystementry.cpp') diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp index 6a655391be..ac1691d30e 100644 --- a/src/corelib/io/qfilesystementry.cpp +++ b/src/corelib/io/qfilesystementry.cpp @@ -14,6 +14,10 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; +// Assigned to m_lastSeparator and m_firstDotInFileName to indicate resolveFilePath() +// hasn't been called yet +constexpr int Uninitialized = -2; + #ifdef Q_OS_WIN static bool isUncRoot(const QString &server) { @@ -51,8 +55,8 @@ QFileSystemEntry::QFileSystemEntry() */ QFileSystemEntry::QFileSystemEntry(const QString &filePath) : m_filePath(QDir::fromNativeSeparators(filePath)), - m_lastSeparator(-2), - m_firstDotInFileName(-2), + m_lastSeparator(Uninitialized), + m_firstDotInFileName(Uninitialized), m_lastDotInFileName(0) { } @@ -64,8 +68,8 @@ QFileSystemEntry::QFileSystemEntry(const QString &filePath) */ QFileSystemEntry::QFileSystemEntry(const QString &filePath, FromInternalPath /* dummy */) : m_filePath(filePath), - m_lastSeparator(-2), - m_firstDotInFileName(-2), + m_lastSeparator(Uninitialized), + m_firstDotInFileName(Uninitialized), m_lastDotInFileName(0) { } @@ -76,8 +80,8 @@ QFileSystemEntry::QFileSystemEntry(const QString &filePath, FromInternalPath /* */ QFileSystemEntry::QFileSystemEntry(const NativePath &nativeFilePath, FromNativePath /* dummy */) : m_nativeFilePath(nativeFilePath), - m_lastSeparator(-2), - m_firstDotInFileName(-2), + m_lastSeparator(Uninitialized), + m_firstDotInFileName(Uninitialized), m_lastDotInFileName(0) { } @@ -85,8 +89,8 @@ QFileSystemEntry::QFileSystemEntry(const NativePath &nativeFilePath, FromNativeP QFileSystemEntry::QFileSystemEntry(const QString &filePath, const NativePath &nativeFilePath) : m_filePath(QDir::fromNativeSeparators(filePath)), m_nativeFilePath(nativeFilePath), - m_lastSeparator(-2), - m_firstDotInFileName(-2), + m_lastSeparator(Uninitialized), + m_firstDotInFileName(Uninitialized), m_lastDotInFileName(0) { } @@ -312,7 +316,7 @@ bool QFileSystemEntry::isEmpty() const void QFileSystemEntry::findLastSeparator() const { - if (m_lastSeparator == -2) { + if (m_lastSeparator == Uninitialized) { resolveFilePath(); m_lastSeparator = m_filePath.lastIndexOf(u'/'); } @@ -320,7 +324,7 @@ void QFileSystemEntry::findLastSeparator() const void QFileSystemEntry::findFileNameSeparators() const { - if (m_firstDotInFileName == -2) { + if (m_firstDotInFileName == Uninitialized) { resolveFilePath(); int firstDotInFileName = -1; int lastDotInFileName = -1; -- cgit v1.2.3