aboutsummaryrefslogtreecommitdiff
path: root/src/common/fs
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2025-08-27 22:21:04 +0200
committercrueter <crueter@eden-emu.dev>2025-08-27 22:21:04 +0200
commit09e77fa146f6630c8a01f59166a572dd58a30d2e (patch)
treec70cd6e7e95bf822e0ec0ece6061cf94d29eb59e /src/common/fs
parentdae0d7bec678253bd5ee5d10690bec5ffbfab024 (diff)
[common, fs] Use std::string_view instead of std::string&; inline functions that are used rarely (#330)
Signed-off-by: lizzie <lizzie@eden-emu.dev> Co-authored-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/330 Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/common/fs')
-rw-r--r--src/common/fs/path_util.cpp20
-rw-r--r--src/common/fs/path_util.h12
2 files changed, 10 insertions, 22 deletions
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index e032360961..fa1403225e 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -517,24 +517,4 @@ std::string_view GetPathWithoutTop(std::string_view path) {
return path.substr(std::min(name_bck_index, name_fwd_index) + 1);
}
-std::string_view GetFilename(std::string_view path) {
- const auto name_index = path.find_last_of("\\/");
-
- if (name_index == std::string_view::npos) {
- return {};
- }
-
- return path.substr(name_index + 1);
-}
-
-std::string_view GetExtensionFromFilename(std::string_view name) {
- const std::size_t index = name.rfind('.');
-
- if (index == std::string_view::npos) {
- return {};
- }
-
- return name.substr(index + 1);
-}
-
} // namespace Common::FS
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h
index c1f478690a..b34efc472f 100644
--- a/src/common/fs/path_util.h
+++ b/src/common/fs/path_util.h
@@ -352,9 +352,17 @@ enum class DirectorySeparator {
[[nodiscard]] std::string_view GetPathWithoutTop(std::string_view path);
// Gets the filename of the path
-[[nodiscard]] std::string_view GetFilename(std::string_view path);
+[[nodiscard]] inline std::string_view GetFilename(const std::string_view path) noexcept {
+ if (auto const name_index = path.find_last_of("\\/"); name_index != std::string_view::npos)
+ return path.substr(name_index + 1);
+ return {};
+}
// Gets the extension of the filename
-[[nodiscard]] std::string_view GetExtensionFromFilename(std::string_view name);
+[[nodiscard]] inline std::string_view GetExtensionFromFilename(const std::string_view name) noexcept {
+ if (auto const index = name.rfind('.'); index != std::string_view::npos)
+ return name.substr(index + 1);
+ return {};
+}
} // namespace Common::FS