Reuse std::locale() across calls within single ifind()

Instantiate the std:locale instance used within the character comparison
callback outside the lambda and take a reference to it instead of
creating the locale object for each character in the sequence.

This is part of a very tight loop with lots of inputs during the
evaluation of fuzzy string matches for completions/autosuggestions and
is worth optimizing.
This commit is contained in:
Mahmoud Al-Qudsi 2018-10-27 18:51:59 -05:00
parent 0d8334a31b
commit 17049ce919

View File

@ -364,8 +364,8 @@ bool string_prefixes_string_case_insensitive(const wcstring &proposed_prefix,
template <typename T>
size_t ifind(const T &haystack, const T &needle) {
using char_t = typename T::value_type;
auto icase_eq = [](char_t c1, char_t c2) {
auto locale = std::locale();
auto locale = std::locale();
auto icase_eq = [&locale](char_t c1, char_t c2) {
return std::toupper(c1, locale) == std::toupper(c2, locale);
};
auto result =