mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 14:10:36 -04:00
Slight optimization for path
This commit is contained in:
parent
12fc84521d
commit
ee4fa2f2de
@ -18,10 +18,7 @@ path::path(const std::string& path){
|
||||
names.push_back("/");
|
||||
}
|
||||
|
||||
auto parts = std::split(path, '/');
|
||||
names.reserve(names.size() + parts.size());
|
||||
|
||||
std::copy(parts.begin(), parts.end(), std::back_inserter(names));
|
||||
std::split_append(path, names, '/');
|
||||
}
|
||||
|
||||
path::path(const path& base_path, const std::string& p){
|
||||
|
@ -658,6 +658,26 @@ std::vector<std::basic_string<Char>> split(const std::basic_string<Char>& s, cha
|
||||
return std::move(parts);
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
void split_append(const std::basic_string<Char>& s, std::vector<std::basic_string<Char>>& container, char sep = ' '){
|
||||
std::basic_string<Char> current(s.size());
|
||||
|
||||
for(char c : s){
|
||||
if(c == sep && !current.empty()){
|
||||
container.push_back(current);
|
||||
current.clear();
|
||||
} else if(c == sep){
|
||||
continue;
|
||||
} else {
|
||||
current += c;
|
||||
}
|
||||
}
|
||||
|
||||
if(!current.empty()){
|
||||
container.push_back(current);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string to_string(const T& value);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user