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 <thiago.macieira@intel.com>
bb10
Ahmad Samir 2023-12-14 23:27:31 +02:00
parent 7c4e271fe7
commit f44c47a301
1 changed files with 14 additions and 10 deletions

View File

@ -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;