Slight optimization for path

This commit is contained in:
Baptiste Wicht 2016-10-03 22:22:27 +02:00
parent 12fc84521d
commit ee4fa2f2de
No known key found for this signature in database
GPG Key ID: C5566B6C7F884532
2 changed files with 21 additions and 4 deletions

View File

@ -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){

View File

@ -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);