mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 12:31:06 -04:00
Reduce more memory allocations for path concat
This commit is contained in:
parent
3351b6fa68
commit
ffca00614e
@ -34,6 +34,11 @@ struct path {
|
||||
*/
|
||||
path(const std::string& path);
|
||||
|
||||
/*!
|
||||
* \brief Construct a path by concatenating a base path and a string path
|
||||
*/
|
||||
path(const path& base_path, const char* path);
|
||||
|
||||
/*!
|
||||
* \brief Construct a path by concatenating a base path and a string path
|
||||
*/
|
||||
|
@ -9,13 +9,9 @@
|
||||
|
||||
#include "assert.hpp"
|
||||
|
||||
path::path(){
|
||||
//Nothing to init
|
||||
}
|
||||
|
||||
path::path(const char* path){
|
||||
thor_assert(path, "Invalid base path");
|
||||
namespace {
|
||||
|
||||
void append_path_to_names(const char* path, std::vector<std::string>& names){
|
||||
size_t i = 0;
|
||||
|
||||
if(path[0] == '/'){
|
||||
@ -43,6 +39,18 @@ path::path(const char* path){
|
||||
}
|
||||
}
|
||||
|
||||
} // end of anonymous namespaces
|
||||
|
||||
path::path(){
|
||||
//Nothing to init
|
||||
}
|
||||
|
||||
path::path(const char* path){
|
||||
thor_assert(path, "Invalid base path");
|
||||
|
||||
append_path_to_names(path, names);
|
||||
}
|
||||
|
||||
path::path(const std::string& path){
|
||||
if(path[0] == '/'){
|
||||
names.push_back("/");
|
||||
@ -51,6 +59,16 @@ path::path(const std::string& path){
|
||||
std::split_append(path, names, '/');
|
||||
}
|
||||
|
||||
path::path(const path& base_path, const char* p){
|
||||
thor_assert(!p || p[0] != '/', "Impossible to add absolute path to another path");
|
||||
|
||||
names.reserve(base_path.size() + 1);
|
||||
|
||||
std::copy(base_path.begin(), base_path.end(), std::back_inserter(names));
|
||||
|
||||
append_path_to_names(p, names);
|
||||
}
|
||||
|
||||
path::path(const path& base_path, const std::string& p){
|
||||
thor_assert(p.empty() || p[0] != '/', "Impossible to add absolute path to another path");
|
||||
|
||||
@ -212,7 +230,7 @@ path operator/(const path& lhs, const std::string& rhs){
|
||||
}
|
||||
|
||||
path operator/(const path& lhs, const char* rhs){
|
||||
return {lhs, path(rhs)};
|
||||
return {lhs, rhs};
|
||||
}
|
||||
|
||||
path operator/(const std::string& lhs, const path& rhs){
|
||||
|
Loading…
x
Reference in New Issue
Block a user