From ed79462d997324d7adfeef21d1ffe386f8603967 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 26 Jul 2018 15:15:55 +0200 Subject: [PATCH] QFSFileEngine::filename(): convert if/else-if chain to a switch Makes clear that this is what it is; and ensures we'll get compiler warnings if someone adds a new entry to the FileName enum without code to handle it here. Change-Id: I36e383066728cefcc75e0a760e36222cebd1dff0 Reviewed-by: Thiago Macieira --- src/corelib/io/qfsfileengine_unix.cpp | 29 +++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index b82415cb265..bf648cdfe04 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -530,29 +530,32 @@ QByteArray QFSFileEngine::id() const QString QFSFileEngine::fileName(FileName file) const { Q_D(const QFSFileEngine); - if (file == BundleName) { + switch (file) { + case BundleName: return QFileSystemEngine::bundleName(d->fileEntry); - } else if (file == BaseName) { + case BaseName: return d->fileEntry.fileName(); - } else if (file == PathName) { + case PathName: return d->fileEntry.path(); - } else if (file == AbsoluteName || file == AbsolutePathName) { + case AbsoluteName: + case AbsolutePathName: { QFileSystemEntry entry(QFileSystemEngine::absoluteName(d->fileEntry)); - if (file == AbsolutePathName) { - return entry.path(); - } - return entry.filePath(); - } else if (file == CanonicalName || file == CanonicalPathName) { + return file == AbsolutePathName ? entry.path() : entry.filePath(); + } + case CanonicalName: + case CanonicalPathName: { QFileSystemEntry entry(QFileSystemEngine::canonicalName(d->fileEntry, d->metaData)); - if (file == CanonicalPathName) - return entry.path(); - return entry.filePath(); - } else if (file == LinkName) { + return file == CanonicalPathName ? entry.path() : entry.filePath(); + } + case LinkName: if (d->isSymlink()) { QFileSystemEntry entry = QFileSystemEngine::getLinkTarget(d->fileEntry, d->metaData); return entry.filePath(); } return QString(); + case DefaultName: + case NFileNames: + break; } return d->fileEntry.filePath(); }