]> granicus.if.org Git - vim/commitdiff
patch 8.2.4732: duplicate code to free fuzzy matches v8.2.4732
authorBram Moolenaar <Bram@vim.org>
Sun, 10 Apr 2022 17:09:06 +0000 (18:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 10 Apr 2022 17:09:06 +0000 (18:09 +0100)
Problem:    Duplicate code to free fuzzy matches.
Solution:   Bring back fuzmatch_str_free().

src/cmdexpand.c
src/proto/search.pro
src/search.c
src/version.c

index ca669c07980e3ad7a52fd975b170bfc97847e91d..9bcea7e8d61de2a445443f3f5cd76b5dccd7ad1c 100644 (file)
@@ -2877,13 +2877,7 @@ ExpandGeneric(
                ga_clear_strings(&ga);
                return FAIL;
            }
-
-           for (i = 0; i < ga.ga_len; ++i)
-           {
-               fuzmatch = &((fuzmatch_str_T *)ga.ga_data)[i];
-               vim_free(fuzmatch->str);
-           }
-           ga_clear(&ga);
+           fuzmatch_str_free(ga.ga_data, ga.ga_len);
            return FAIL;
        }
 
index 0548fcadd8e9fb280711129e00c1e8ed7d62ff62..8fa01da9b94928cda69fd15c00bb1c2d5f673b4c 100644 (file)
@@ -41,5 +41,6 @@ int fuzzy_match(char_u *str, char_u *pat_arg, int matchseq, int *outScore, int_u
 void f_matchfuzzy(typval_T *argvars, typval_T *rettv);
 void f_matchfuzzypos(typval_T *argvars, typval_T *rettv);
 int fuzzy_match_str(char_u *str, char_u *pat);
-int fuzzymatches_to_strmatches(fuzmatch_str_T *fuzmatch, char_u ***matches, int        count, int funcsort);
+void fuzmatch_str_free(fuzmatch_str_T *fuzmatch, int count);
+int fuzzymatches_to_strmatches(fuzmatch_str_T *fuzmatch, char_u ***matches, int count, int funcsort);
 /* vim: set ft=c : */
index 6a52415e71e3dcf45ff11d99bb4d98a0e04f93f7..470bde21468bfa2b358f52fae3be4f51fbbfecb2 100644 (file)
@@ -5013,6 +5013,21 @@ fuzzy_match_str(char_u *str, char_u *pat)
     return score;
 }
 
+/*
+ * Free an array of fuzzy string matches "fuzmatch[count]".
+ */
+    void
+fuzmatch_str_free(fuzmatch_str_T *fuzmatch, int count)
+{
+    int i;
+
+    if (fuzmatch == NULL)
+       return;
+    for (i = 0; i < count; ++i)
+       vim_free(fuzmatch[i].str);
+    vim_free(fuzmatch);
+}
+
 /*
  * Copy a list of fuzzy matches into a string list after sorting the matches by
  * the fuzzy score. Frees the memory allocated for 'fuzmatch'.
@@ -5033,9 +5048,7 @@ fuzzymatches_to_strmatches(
     *matches = ALLOC_MULT(char_u *, count);
     if (*matches == NULL)
     {
-       for (i = 0; i < count; i++)
-           vim_free(fuzmatch[i].str);
-       vim_free(fuzmatch);
+       fuzmatch_str_free(fuzmatch, count);
        return FAIL;
     }
 
index 57e1fedafdb78d23a53a8381d4cbdcb5990aafc2..95486ba33a9da1c4d5e61403a3efbee6cdd31e49 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4732,
 /**/
     4731,
 /**/