From a819cb54a6a7c15bc42ab8334e32b78754f33f12 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Fri, 3 Mar 2017 19:37:19 +0100 Subject: [PATCH] Config: Use set for preloadScripts Would probably make sense for all other string vectors too. --- binding-mri/binding-mri.cpp | 5 +++-- src/config.cpp | 8 +++++++- src/config.h | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 5cb518e..c28cdaa 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -452,8 +452,9 @@ static void runRMXPScripts(BacktraceData &btData) } /* Execute preloaded scripts */ - for (size_t i = 0; i < conf.preloadScripts.size(); ++i) - runCustomScript(conf.preloadScripts[i]); + for (std::set::iterator i = conf.preloadScripts.begin(); + i != conf.preloadScripts.end(); ++i) + runCustomScript(*i); VALUE exc = rb_gv_get("$!"); if (exc != Qnil) diff --git a/src/config.cpp b/src/config.cpp index 9173acc..a58ddab 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -134,6 +134,12 @@ static std::string prefPath(const char *org, const char *app) return str; } +template +std::set setFromVec(const std::vector &vec) +{ + return std::set(vec.begin(), vec.end()); +} + typedef std::vector StringVec; namespace po = boost::program_options; @@ -226,7 +232,7 @@ void Config::read(int argc, char *argv[]) PO_DESC_ALL; - GUARD_ALL( preloadScripts = vm["preloadScript"].as(); ); + GUARD_ALL( preloadScripts = setFromVec(vm["preloadScript"].as()); ); GUARD_ALL( rtps = vm["RTP"].as(); ); diff --git a/src/config.h b/src/config.h index fc9bbda..d82698d 100644 --- a/src/config.h +++ b/src/config.h @@ -24,6 +24,7 @@ #include #include +#include struct Config { @@ -77,7 +78,7 @@ struct Config bool useScriptNames; std::string customScript; - std::vector preloadScripts; + std::set preloadScripts; std::vector rtps; std::vector fontSubs;