refactor: rename ga_concat_strings_sep() to ga_concat_strings() (#35498)

This adds a missing change from Vim patch 7.4.279.

N/A patch:
vim-patch:9.1.1691: over-allocation in ga_concat_strings()
This commit is contained in:
zeertzjq
2025-08-27 10:17:12 +08:00
committed by GitHub
parent 4263ec21c2
commit 443278c587
5 changed files with 13 additions and 41 deletions

View File

@@ -574,7 +574,7 @@ void f_globpath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags, false); globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags, false);
if (rettv->v_type == VAR_STRING) { if (rettv->v_type == VAR_STRING) {
rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n"); rettv->vval.v_string = ga_concat_strings(&ga, "\n");
} else { } else {
tv_list_alloc_ret(rettv, ga.ga_len); tv_list_alloc_ret(rettv, ga.ga_len);
for (int i = 0; i < ga.ga_len; i++) { for (int i = 0; i < ga.ga_len; i++) {

View File

@@ -124,13 +124,13 @@ void ga_remove_duplicate_strings(garray_T *gap)
} }
/// For a growing array that contains a list of strings: concatenate all the /// For a growing array that contains a list of strings: concatenate all the
/// strings with sep as separator. /// strings with "sep" as separator.
/// ///
/// @param gap /// @param gap
/// @param sep /// @param sep
/// ///
/// @returns the concatenated strings /// @returns the concatenated strings
char *ga_concat_strings_sep(const garray_T *gap, const char *sep) char *ga_concat_strings(const garray_T *gap, const char *sep)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_RET
{ {
const size_t nelem = (size_t)gap->ga_len; const size_t nelem = (size_t)gap->ga_len;
@@ -159,17 +159,6 @@ char *ga_concat_strings_sep(const garray_T *gap, const char *sep)
return ret; return ret;
} }
/// For a growing array that contains a list of strings: concatenate all the
/// strings with a separating comma.
///
/// @param gap
///
/// @returns the concatenated strings
char *ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET
{
return ga_concat_strings_sep(gap, ",");
}
/// Concatenate a string to a growarray which contains characters. /// Concatenate a string to a growarray which contains characters.
/// When "s" is NULL does not do anything. /// When "s" is NULL does not do anything.
/// ///

View File

@@ -1472,7 +1472,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name
void nlua_exec_ga(garray_T *ga, char *name) void nlua_exec_ga(garray_T *ga, char *name)
{ {
char *code = ga_concat_strings_sep(ga, "\n"); char *code = ga_concat_strings(ga, "\n");
size_t len = strlen(code); size_t len = strlen(code);
nlua_typval_exec(code, len, name, NULL, 0, false, NULL); nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
xfree(code); xfree(code);

View File

@@ -1145,7 +1145,7 @@ static int expand_in_path(garray_T *const gap, char *const pattern, const int fl
return 0; return 0;
} }
char *const paths = ga_concat_strings(&path_ga); char *const paths = ga_concat_strings(&path_ga, ",");
ga_clear_strings(&path_ga); ga_clear_strings(&path_ga);
int glob_flags = 0; int glob_flags = 0;

View File

@@ -93,12 +93,8 @@ local ga_append = function(garr, b)
end end
end end
local ga_concat_strings = function(garr) local ga_concat_strings = function(garr, sep)
return internalize(garray.ga_concat_strings(garr)) return internalize(garray.ga_concat_strings(garr, to_cstr(sep)))
end
local ga_concat_strings_sep = function(garr, sep)
return internalize(garray.ga_concat_strings_sep(garr, to_cstr(sep)))
end end
local ga_remove_duplicate_strings = function(garr) local ga_remove_duplicate_strings = function(garr)
@@ -320,19 +316,16 @@ describe('garray', function()
end) end)
end) end)
local function test_concat_fn(input, fn, sep) local function test_concat_fn(input, sep)
local garr = new_string_garray() local garr = new_string_garray()
ga_append_strings(garr, unpack(input)) ga_append_strings(garr, unpack(input))
if sep == nil then eq(table.concat(input, sep), ga_concat_strings(garr, sep))
eq(table.concat(input, ','), fn(garr))
else
eq(table.concat(input, sep), fn(garr, sep))
end
end end
describe('ga_concat_strings', function() describe('ga_concat_strings', function()
itp('returns an empty string when concatenating an empty array', function() itp('returns an empty string when concatenating an empty array', function()
test_concat_fn({}, ga_concat_strings) test_concat_fn({}, ',')
test_concat_fn({}, '---')
end) end)
itp('can concatenate a non-empty array', function() itp('can concatenate a non-empty array', function()
@@ -340,22 +333,12 @@ describe('garray', function()
'oh', 'oh',
'my', 'my',
'neovim', 'neovim',
}, ga_concat_strings) }, ',')
end)
end)
describe('ga_concat_strings_sep', function()
itp('returns an empty string when concatenating an empty array', function()
test_concat_fn({}, ga_concat_strings_sep, '---')
end)
itp('can concatenate a non-empty array', function()
local sep = '-●●-'
test_concat_fn({ test_concat_fn({
'oh', 'oh',
'my', 'my',
'neovim', 'neovim',
}, ga_concat_strings_sep, sep) }, '-●●-')
end) end)
end) end)