Use g_string_new_take().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-12-23 16:54:53 +03:00
parent 2019737846
commit 2d86b8889f
6 changed files with 48 additions and 9 deletions

View File

@ -140,6 +140,41 @@ g_queue_clear_full (GQueue * queue, GDestroyNotify free_func)
/* --------------------------------------------------------------------------------------------- */
#if ! GLIB_CHECK_VERSION (2, 77, 0)
/**
* g_string_new_take:
* @init: (nullable): initial text used as the string.
* Ownership of the string is transferred to the #GString.
* Passing NULL creates an empty string.
*
* Creates a new #GString, initialized with the given string.
*
* After this call, @init belongs to the #GString and may no longer be
* modified by the caller. The memory of @data has to be dynamically
* allocated and will eventually be freed with g_free().
*
* Returns: the new #GString
*/
GString *
g_string_new_take (char *init)
{
GString *string;
if (init == NULL)
return g_string_new (NULL);
string = g_slice_new (GString);
string->str = init;
string->len = strlen (string->str);
string->allocated_len = string->len + 1;
return string;
}
#endif /* ! GLIB_CHECK_VERSION (2, 77, 0) */
/* --------------------------------------------------------------------------------------------- */
/**
* mc_g_string_copy:
* @dest: (not nullable): the destination #GString. Its current contents are destroyed

View File

@ -25,6 +25,10 @@ void g_clear_list (GList ** list_ptr, GDestroyNotify destroy);
void g_queue_clear_full (GQueue * queue, GDestroyNotify free_func);
#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */
#if ! GLIB_CHECK_VERSION (2, 77, 0)
GString *g_string_new_take (char *init);
#endif /* ! GLIB_CHECK_VERSION (2, 77, 0) */
/* There is no such API in GLib2 */
GString *mc_g_string_copy (GString * dest, const GString * src);

View File

@ -873,7 +873,8 @@ edit_replace_cmd (WEdit * edit, gboolean again)
edit->search = NULL;
}
input2_str = g_string_new (input2);
input2_str = g_string_new_take (input2);
input2 = NULL;
if (edit->search == NULL)
{

View File

@ -1015,8 +1015,7 @@ setup_cmdline (void)
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
{
subshell_prompt = g_string_new (tmp_prompt);
g_free (tmp_prompt);
subshell_prompt = g_string_new_take (tmp_prompt);
mc_prompt = subshell_prompt->str;
}
#endif

View File

@ -2353,8 +2353,7 @@ goto_parent_dir (WPanel * panel)
mc_build_filename (vfs_path_as_str (panel->panelized_descr->root_vpath), fname->str,
(char *) NULL);
fname = g_string_new (fname2);
g_free (fname2);
fname = g_string_new_take (fname2);
}
bname = x_basename (fname->str);
@ -5243,8 +5242,7 @@ panel_panelize_cd (void)
tmp_vpath =
vfs_path_append_new (pdescr->root_vpath, plist->list[i].fname->str, (char *) NULL);
list->list[i].fname = g_string_new (vfs_path_as_str (tmp_vpath));
vfs_path_free (tmp_vpath, TRUE);
list->list[i].fname = g_string_new_take (vfs_path_free (tmp_vpath, FALSE));
}
list->list[i].f.link_to_dir = plist->list[i].f.link_to_dir;
list->list[i].f.stale_link = plist->list[i].f.stale_link;

View File

@ -939,12 +939,14 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote)
if (tmp != NULL)
{
if (block == NULL)
block = g_string_new (tmp);
block = g_string_new_take (tmp);
else
{
g_string_append (block, tmp);
g_string_append_c (block, ' ');
g_free (tmp);
}
g_string_append_c (block, ' ');
}
if (c_lc == 'u')
do_file_mark (panel, i, 0);