mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-01 00:54:24 +03:00
Create strings with small preallocated sizes.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
69cebb9984
commit
b6fd832a8a
@ -51,10 +51,12 @@ static GString *
|
||||
mc_search__glob_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
GString *buff;
|
||||
gsize loop = 0;
|
||||
gboolean inside_group = FALSE;
|
||||
|
||||
buff = g_string_sized_new (32);
|
||||
|
||||
while (loop < astr->len)
|
||||
{
|
||||
switch (str[loop])
|
||||
@ -124,9 +126,12 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
||||
static GString *
|
||||
mc_search__translate_replace_glob_to_regex (gchar * str)
|
||||
{
|
||||
GString *buff = g_string_sized_new (32);
|
||||
GString *buff;
|
||||
int cnt = '0';
|
||||
gboolean escaped_mode = FALSE;
|
||||
|
||||
buff = g_string_sized_new (32);
|
||||
|
||||
while (*str)
|
||||
{
|
||||
char c = *str++;
|
||||
|
@ -52,12 +52,13 @@ static GString *
|
||||
mc_search__hex_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
gchar *tmp_str = g_strndup (str, astr->len);
|
||||
gchar *tmp_str2;
|
||||
GString *buff;
|
||||
gchar *tmp_str, *tmp_str2;
|
||||
gsize loop = 0;
|
||||
int val, ptr;
|
||||
|
||||
buff = g_string_sized_new (64);
|
||||
tmp_str = g_strndup (str, astr->len);
|
||||
g_strchug (tmp_str); /* trim leadind whitespaces */
|
||||
|
||||
while (loop < astr->len) {
|
||||
|
@ -49,9 +49,11 @@ static GString *
|
||||
mc_search__normal_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
GString *buff;
|
||||
gsize loop = 0;
|
||||
|
||||
buff = g_string_sized_new (32);
|
||||
|
||||
while (loop < astr->len) {
|
||||
switch (str[loop]) {
|
||||
case '*':
|
||||
|
@ -199,9 +199,9 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *ast
|
||||
GString *accumulator, *spec_char, *ret_str;
|
||||
gsize loop;
|
||||
|
||||
ret_str = g_string_new ("");
|
||||
accumulator = g_string_new ("");
|
||||
spec_char = g_string_new ("");
|
||||
ret_str = g_string_sized_new (64);
|
||||
accumulator = g_string_sized_new (64);
|
||||
spec_char = g_string_sized_new (64);
|
||||
loop = 0;
|
||||
|
||||
while (loop <= astr->len)
|
||||
@ -584,7 +584,7 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
if (lc_mc_search->regex_buffer != NULL)
|
||||
g_string_free (lc_mc_search->regex_buffer, TRUE);
|
||||
|
||||
lc_mc_search->regex_buffer = g_string_new ("");
|
||||
lc_mc_search->regex_buffer = g_string_sized_new (64);
|
||||
|
||||
virtual_pos = current_pos = start_search;
|
||||
while (virtual_pos <= end_search)
|
||||
@ -696,8 +696,9 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = g_string_new ("");
|
||||
ret = g_string_sized_new (64);
|
||||
prev_str = replace_str->str;
|
||||
|
||||
for (loop = 0; loop < replace_str->len - 1; loop++)
|
||||
{
|
||||
lc_index = mc_search_regex__process_replace_str (replace_str, loop, &len, &replace_flags);
|
||||
|
@ -339,12 +339,12 @@ char *
|
||||
mc_search_prepare_replace_str2 (mc_search_t * lc_mc_search, char *replace_str)
|
||||
{
|
||||
GString *ret;
|
||||
GString *replace_str2 = g_string_new (replace_str);
|
||||
GString *replace_str2;
|
||||
|
||||
replace_str2 = g_string_new (replace_str);
|
||||
ret = mc_search_prepare_replace_str (lc_mc_search, replace_str2);
|
||||
g_string_free (replace_str2, TRUE);
|
||||
if (ret)
|
||||
return g_string_free (ret, FALSE);
|
||||
return NULL;
|
||||
return (ret != NULL) ? g_string_free (ret, FALSE) : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user