From b43f0fb8530b45298cdd3da2fdebe6c2fa43b5d4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 16 Nov 2014 20:55:36 +0000 Subject: [PATCH] Yet more StringView params, less const String& --- src/option_manager.cc | 6 +++--- src/option_manager.hh | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/option_manager.cc b/src/option_manager.cc index 5330e05a..34f30d92 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -39,7 +39,7 @@ void OptionManager::unregister_watcher(OptionManagerWatcher& watcher) m_watchers.erase(it); } -Option& OptionManager::get_local_option(const String& name) +Option& OptionManager::get_local_option(StringView name) { auto it = find_option(m_options, name); if (it != m_options.end()) @@ -54,7 +54,7 @@ Option& OptionManager::get_local_option(const String& name) } -Option& OptionManager::operator[](const String& name) +Option& OptionManager::operator[](StringView name) { auto it = find_option(m_options, name); if (it != m_options.end()) @@ -65,7 +65,7 @@ Option& OptionManager::operator[](const String& name) throw option_not_found(name); } -const Option& OptionManager::operator[](const String& name) const +const Option& OptionManager::operator[](StringView name) const { return const_cast(*this)[name]; } diff --git a/src/option_manager.hh b/src/option_manager.hh index be60bf47..a153a097 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -55,8 +55,8 @@ public: template bool is_of_type() const; virtual String get_as_string() const = 0; - virtual void set_from_string(const String& str) = 0; - virtual void add_from_string(const String& str) = 0; + virtual void set_from_string(StringView str) = 0; + virtual void add_from_string(StringView str) = 0; virtual Option* clone(OptionManager& manager) const = 0; OptionManager& manager() const { return m_manager; } @@ -86,9 +86,9 @@ public: OptionManager(OptionManager& parent); ~OptionManager(); - Option& operator[] (const String& name); - const Option& operator[] (const String& name) const; - Option& get_local_option(const String& name); + Option& operator[] (StringView name); + const Option& operator[] (StringView name) const; + Option& get_local_option(StringView name); CandidateList complete_option_name(StringView prefix, ByteCount cursor_pos); @@ -137,13 +137,13 @@ public: { return option_to_string(m_value); } - void set_from_string(const String& str) override + void set_from_string(StringView str) override { T val; option_from_string(str, val); set(std::move(val)); } - void add_from_string(const String& str) override + void add_from_string(StringView str) override { T val; option_from_string(str, val); @@ -181,7 +181,7 @@ template bool Option::is_of_type() const } template -auto find_option(T& container, const String& name) -> decltype(container.begin()) +auto find_option(T& container, StringView name) -> decltype(container.begin()) { using ptr_type = decltype(*container.begin()); return find_if(container, [&name](const ptr_type& opt) { return opt->name() == name; });