From 87997f6285fdba420c00e740d26f98f7e7e06504 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 7 Dec 2024 16:51:49 +0100 Subject: Create sources from string_views instead of const char* and std::strings. --- src/ctor.h | 16 +++++++--------- src/rebuild.cc | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ctor.h b/src/ctor.h index 3b64cb5..8204f70 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -54,15 +54,13 @@ enum class arch struct source { - source(const char* file) : file(file) {} - source(const std::string& file) : file(file) {} - source(const char* file, ctor::language lang) : file(file), language(lang) {} - source(const std::string& file, ctor::language lang) : file(file), language(lang) {} - - source(const char* file, const char* output) : file(file), output(output) {} - source(const std::string& file, const std::string& output) : file(file), output(output) {} - source(const char* file, ctor::language lang, const char* output) : file(file), language(lang), output(output) {} - source(const std::string& file, ctor::language lang, const std::string& output) : file(file), language(lang), output(output) {} + constexpr source(const char* file) : file(file) {} // convenience ctor + + constexpr source(std::string_view file) : source(file, ctor::language::automatic) {} + constexpr source(std::string_view file, ctor::language lang) : file(file), language(lang) {} + + constexpr source(std::string_view file, std::string_view output) : file(file), output(output) {} + constexpr source(std::string_view file, ctor::language lang, std::string_view output) : file(file), language(lang), output(output) {} std::string file; ctor::language language{ctor::language::automatic}; diff --git a/src/rebuild.cc b/src/rebuild.cc index f0d52d9..76fcbef 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -192,7 +192,7 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ if(std::filesystem::exists(configurationFile)) { - config.sources.push_back(configurationFile.string()); + config.sources.emplace_back(configurationFile.string()); } for(std::size_t i = 0; i < numConfigFiles; ++i) @@ -206,7 +206,7 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ // Ensure that files containing multiple configurations are only added once. if(!contains(config.sources, location)) { - config.sources.push_back(location); + config.sources.emplace_back(location); } } @@ -221,7 +221,7 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ // Ensure that files containing multiple configurations are only added once. if(!contains(config.sources, location)) { - config.sources.push_back(location); + config.sources.emplace_back(location); } } -- cgit v1.2.3