From 20b98294ba54ebb61ecd5e663d9263b9f5cd0c4a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 27 Nov 2020 20:34:47 -0800 Subject: [PATCH] Bravely remove string_fuzzy_match_t::compare This is used to decide which fuzzy match is better, however it is used only in wildcard expansion and not in actual completion ranking or anywhere else where it could matter. Try removing the compare() call and implementation. What compare() did specially was compare distances, e.g. it ranks lib as better than libexec when expanding /u/l/b. But the tests did not exercise this so it's hard to know if it's working. In preparation for a refactoring, remove it. --- src/wcstringutil.cpp | 19 ------------------- src/wcstringutil.h | 3 --- src/wildcard.cpp | 3 ++- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/wcstringutil.cpp b/src/wcstringutil.cpp index 7e77740af..d83e3e6cd 100644 --- a/src/wcstringutil.cpp +++ b/src/wcstringutil.cpp @@ -202,25 +202,6 @@ string_fuzzy_match_t string_fuzzy_match_string(const wcstring &string, return result; } -template -static inline int compare_ints(T a, T b) { - if (a < b) return -1; - if (a == b) return 0; - return 1; -} - -/// Compare types; if the types match, compare distances. -int string_fuzzy_match_t::compare(const string_fuzzy_match_t &rhs) const { - if (this->type != rhs.type) { - return compare_ints(this->type, rhs.type); - } else if (this->match_distance_first != rhs.match_distance_first) { - return compare_ints(this->match_distance_first, rhs.match_distance_first); - } else if (this->match_distance_second != rhs.match_distance_second) { - return compare_ints(this->match_distance_second, rhs.match_distance_second); - } - return 0; // equal -} - template size_t ifind_impl(const T &haystack, const T &needle) { using char_t = typename T::value_type; diff --git a/src/wcstringutil.h b/src/wcstringutil.h index 2bc93b606..5e81071d4 100644 --- a/src/wcstringutil.h +++ b/src/wcstringutil.h @@ -111,9 +111,6 @@ struct string_fuzzy_match_t { // Constructor. explicit string_fuzzy_match_t(enum fuzzy_type_t t, size_t distance_first = 0, size_t distance_second = 0); - - // Return -1, 0, 1 if this match is (respectively) better than, equal to, or worse than rhs. - int compare(const string_fuzzy_match_t &rhs) const; }; /// Compute a fuzzy match for a string. If maximum_match is not fuzzy_match_t::none, limit the type diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 91ce154c8..2943cd396 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -851,7 +851,8 @@ void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(const wc c->prepend_token_prefix(child_prefix); } // And every match must be made at least as fuzzy as ours. - if (match.compare(c->match) > 0) { + // TODO: justify this, tests do not exercise it yet. + if (match.type > c->match.type) { // Our match is fuzzier. c->match = match; }