From 8a7e16cec379f3f52a30ab2ce35b515914cdfcb4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 7 Oct 2014 21:11:55 +0100 Subject: [PATCH] Switch some const String& parameters to StringView --- src/insert_completer.cc | 2 +- src/insert_completer.hh | 2 +- src/option_types.hh | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index b5be9c95..1e50d189 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -31,7 +31,7 @@ String option_to_string(const InsertCompleterDesc& opt) return ""; } -void option_from_string(const String& str, InsertCompleterDesc& opt) +void option_from_string(StringView str, InsertCompleterDesc& opt) { if (str.substr(0_byte, 7_byte) == "option=") { diff --git a/src/insert_completer.hh b/src/insert_completer.hh index 88759edf..d7580b64 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -37,7 +37,7 @@ using InsertCompleterDescList = std::vector; String option_to_string(const InsertCompleterDesc& opt); -void option_from_string(const String& str, InsertCompleterDesc& opt); +void option_from_string(StringView str, InsertCompleterDesc& opt); struct InsertCompletion { diff --git a/src/option_types.hh b/src/option_types.hh index 7b0ebbf1..ea3bd49a 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -13,15 +13,15 @@ namespace Kakoune { -inline String option_to_string(const String& opt) { return opt; } -inline void option_from_string(const String& str, String& opt) { opt = str; } +inline String option_to_string(StringView opt) { return opt; } +inline void option_from_string(StringView str, String& opt) { opt = str; } inline String option_to_string(int opt) { return to_string(opt); } -inline void option_from_string(const String& str, int& opt) { opt = str_to_int(str); } +inline void option_from_string(StringView str, int& opt) { opt = str_to_int(str); } inline bool option_add(int& opt, int val) { opt += val; return val != 0; } inline String option_to_string(bool opt) { return opt ? "true" : "false"; } -inline void option_from_string(const String& str, bool& opt) +inline void option_from_string(StringView str, bool& opt) { if (str == "true" or str == "yes") opt = true; @@ -47,7 +47,7 @@ String option_to_string(const std::vector& opt) } template -void option_from_string(const String& str, std::vector& opt) +void option_from_string(StringView str, std::vector& opt) { opt.clear(); std::vector elems = split(str, list_separator, '\\'); @@ -80,7 +80,7 @@ String option_to_string(const std::unordered_set& opt) } template -void option_from_string(const String& str, std::unordered_set& opt) +void option_from_string(StringView str, std::unordered_set& opt) { opt.clear(); std::vector elems = split(str, list_separator, '\\'); @@ -138,7 +138,7 @@ String option_to_string(const std::tuple& opt) } template -void option_from_string(const String& str, std::tuple& opt) +void option_from_string(StringView str, std::tuple& opt) { auto elems = split(str, tuple_separator, '\\'); if (elems.size() != sizeof...(Types)) @@ -153,7 +153,7 @@ inline String option_to_string(const StronglyTypedNumber& o } template -inline void option_from_string(const String& str, StronglyTypedNumber& opt) +inline void option_from_string(StringView str, StronglyTypedNumber& opt) { opt = StronglyTypedNumber{str_to_int(str)}; } @@ -173,7 +173,7 @@ bool option_add(T&, const T&) } template -inline void option_from_string(const String& str, LineAndColumn& opt) +inline void option_from_string(StringView str, LineAndColumn& opt) { auto vals = split(str, tuple_separator); if (vals.size() != 2) @@ -207,7 +207,7 @@ inline String option_to_string(YesNoAsk opt) return "ask"; } -inline void option_from_string(const String& str, YesNoAsk& opt) +inline void option_from_string(StringView str, YesNoAsk& opt) { if (str == "yes" or str == "true") opt = Yes;