utils-file: don't use regexp in join_paths
It's slow.
This commit is contained in:
@ -157,16 +157,38 @@ std::string runtime_path(RuntimePath path, const std::string& muhome="");
|
|||||||
* @return the path
|
* @return the path
|
||||||
*/
|
*/
|
||||||
static inline std::string join_paths() { return {}; }
|
static inline std::string join_paths() { return {}; }
|
||||||
template<typename S, typename...Args>
|
template<typename S> std::string join_paths_(S&& s) { return std::string{s}; }
|
||||||
std::string join_paths(S&& s, Args...args) {
|
template<typename S, typename...Args>
|
||||||
|
std::string join_paths_(S&& s, Args...args) {
|
||||||
|
|
||||||
static std::string sepa{"/"};
|
static std::string sepa{"/"};
|
||||||
auto&& str{std::string{std::forward<S>(s)}};
|
auto&& str{std::string{std::forward<S>(s)}};
|
||||||
if (auto&& rest{join_paths(std::forward<Args>(args)...)}; !rest.empty())
|
if (auto&& rest{join_paths_(std::forward<Args>(args)...)}; !rest.empty())
|
||||||
str += (sepa + rest);
|
str += (sepa + rest);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
static auto rx = Regex::make("//*").value();
|
template<typename S, typename...Args>
|
||||||
return rx.replace(str, sepa);
|
std::string join_paths(S&& s, Args...args) {
|
||||||
|
|
||||||
|
constexpr auto sepa = '/';
|
||||||
|
auto path = join_paths_(std::forward<S>(s), std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
auto c{0U};
|
||||||
|
while (c < path.size()) {
|
||||||
|
|
||||||
|
if (path[c] != sepa) {
|
||||||
|
++c;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (path[++c] == '/') {
|
||||||
|
path.erase(c, 1);
|
||||||
|
--c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user