diff --git a/src/escape.cc b/src/escape.cc index d9c45c72..19426270 100644 --- a/src/escape.cc +++ b/src/escape.cc @@ -83,13 +83,14 @@ std::string unescape(string_view in) auto rit = std::regex_iterator{ in.cbegin(), in.cend(), re }; auto const rend = std::regex_iterator{ }; auto last = decltype(*rit){ }; - - if (rit == rend) - return std::string{ in }; - auto unescaped = ""s; unescaped.reserve(in.length()); + if (rit == rend) { + unescaped.assign(in.data(), in.size()); + return unescaped; + } + for (; rit != rend; ++rit) { last = *rit; unescaped += rit->prefix(); diff --git a/src/meson.build b/src/meson.build index a2692485..bcb164db 100644 --- a/src/meson.build +++ b/src/meson.build @@ -99,6 +99,9 @@ endif if meson.get_compiler('cpp').has_argument('-Wconversion') # msvc doesnt have add_cpp_args += [ '-Wconversion' ] endif +if meson.get_compiler('cpp').has_argument('-Wnrvo') # msvc: included in permissive- + add_cpp_args += [ '-Wnrvo' ] +endif deps = dependency('threads') diff --git a/src/replace.cc b/src/replace.cc index 68449c21..b3374afd 100644 --- a/src/replace.cc +++ b/src/replace.cc @@ -28,11 +28,12 @@ namespace gul14 { std::string replace(string_view haystack, string_view needle, string_view hammer) { - if (needle.empty()) - return std::string(haystack); - auto result = ""s; result.reserve(haystack.length()); + if (needle.empty()) { + result.assign(haystack.data(), haystack.length()); + return result; + } std::size_t pos = 0; std::size_t last_pos = 0;