diff options
author | hjk <hjk@qt.io> | 2022-11-23 12:53:04 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-24 16:52:57 +0000 |
commit | a94f37c8b06350cba94c3a4b6221f6df0a8398b4 (patch) | |
tree | c3035315efc9327f8284e470fd273b673d297e1c /src/libs | |
parent | 46cfdbf285aedf6cbeab80f0475901fc8309acad (diff) |
Utils: Add FilePath::{suffix,fileName}View functions
Can save a few cycles in some cases.
Change-Id: I0da3ad9ae2127e20f8e90d68f924e87661028071
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/utils/filepath.cpp | 24 | ||||
-rw-r--r-- | src/libs/utils/filepath.h | 2 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 55e0d8fb27..b6cef68bde 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -248,10 +248,15 @@ QString FilePath::nativePath() const return data; } -QString FilePath::fileName() const +QStringView FilePath::fileNameView() const { const QStringView fp = pathView(); - return fp.mid(fp.lastIndexOf('/') + 1).toString(); + return fp.mid(fp.lastIndexOf('/') + 1); +} + +QString FilePath::fileName() const +{ + return fileNameView().toString(); } QString FilePath::fileNameWithPathComponents(int pathComponents) const @@ -313,17 +318,22 @@ QString FilePath::completeBaseName() const /// (but not including) the last '.'. In case of ".ui.qml" it will /// be treated as one suffix. -QString FilePath::suffix() const +QStringView FilePath::suffixView() const { - const QString &name = fileName(); - if (name.endsWith(".ui.qml")) - return "ui.qml"; + const QStringView name = fileNameView(); + if (name.endsWith(u".ui.qml")) + return u"ui.qml"; const int index = name.lastIndexOf('.'); if (index >= 0) return name.mid(index + 1); return {}; } +QString FilePath::suffix() const +{ + return suffixView().toString(); +} + /// \returns the complete suffix (extension) of the file. /// /// The complete suffix consists of all characters in the file after @@ -572,7 +582,7 @@ static FilePaths appendExeExtensions(const Environment &env, const FilePath &exe if (executable.osType() == OsTypeWindows) { // Check all the executable extensions on windows: // PATHEXT is only used if the executable has no extension - if (executable.suffix().isEmpty()) { + if (executable.suffixView().isEmpty()) { const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';'); for (const QString &ext : extensions) diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 429be2619c..2e0f45b29d 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -81,11 +81,13 @@ public: void setParts(const QStringView scheme, const QStringView host, const QStringView path); QString fileName() const; + QStringView fileNameView() const; QString fileNameWithPathComponents(int pathComponents) const; QString baseName() const; QString completeBaseName() const; QString suffix() const; + QStringView suffixView() const; QString completeSuffix() const; [[nodiscard]] FilePath pathAppended(const QString &str) const; |