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

Simplify len_common_prefix

This commit is contained in:
docentYT
2026-05-01 13:57:33 +02:00
parent 664c340d84
commit 9c27b54960
4 changed files with 6 additions and 9 deletions

View File

@@ -237,7 +237,7 @@ void itemproperties_panel::update_group()
for (auto const &name : names)
{
// NOTE: first calculation runs over two instances of the same name, but, eh
auto const prefixlength{len_common_prefix(m_groupprefix, name)};
auto const prefixlength{len_common_prefix(m_groupprefix, name.get())};
if (prefixlength > 0)
{
m_groupprefix = m_groupprefix.substr(0, prefixlength);

View File

@@ -412,7 +412,7 @@ auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject *
return lookup->second;
}
// try to load specified renderer class
auto const path{substr_path(Renderer)};
std::string const path{substr_path(Renderer)};
auto const file{Renderer.substr(path.size())};
PyObject *renderer{nullptr};
PyObject *rendererarguments{nullptr};

View File

@@ -398,13 +398,10 @@ std::string_view substr_path(std::string const &Filename)
}
// returns length of common prefix between two provided strings
std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right)
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b)
{
auto const *left{Left.data()};
auto const *right{Right.data()};
// compare up to the length of the shorter string
return (Right.size() <= Left.size() ? std::distance(right, std::mismatch(right, right + Right.size(), left).first) : std::distance(left, std::mismatch(left, left + Left.size(), right).first));
auto [it1, it2] = std::ranges::mismatch(a, b);
return std::distance(a.begin(), it1);
}
// returns true if provided string ends with another provided string

View File

@@ -224,7 +224,7 @@ void replace_slashes(std::string &Filename);
std::string_view substr_path(std::string const &Filename);
// returns common prefix of two provided strings
std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right);
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b);
// returns true if provided string ends with another provided string
bool ends_with(std::string_view String, std::string_view Suffix);