16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Optimize substr_path implementation and change return type to sd::string

This commit is contained in:
docentYT
2026-05-07 12:59:57 +02:00
parent f4f4897798
commit 6542021253
2 changed files with 6 additions and 3 deletions

View File

@@ -392,9 +392,12 @@ void replace_slashes(std::string &Filename)
} }
// returns potential path part from provided file name // returns potential path part from provided file name
std::string_view substr_path(std::string const &Filename) std::string substr_path(std::string const &Filename)
{ {
return (Filename.rfind('/') != std::string::npos ? Filename.substr(0, Filename.rfind('/') + 1) : ""); // String::substr returns new string so substr_path has to return std::string
if (auto pos = Filename.rfind('/'); pos != std::string::npos)
return Filename.substr(0, pos + 1);
return {};
} }
// returns length of common prefix between two provided strings // returns length of common prefix between two provided strings

View File

@@ -214,7 +214,7 @@ void erase_leading_slashes(std::string &Filename);
void replace_slashes(std::string &Filename); void replace_slashes(std::string &Filename);
// returns potential path part from provided file name // returns potential path part from provided file name
std::string_view substr_path(std::string const &Filename); std::string substr_path(std::string const &Filename);
// returns common prefix of two provided strings // returns common prefix of two provided strings
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b); std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b);