Skip to content

Commit

Permalink
use buffer pool in config/*
Browse files Browse the repository at this point in the history
  • Loading branch information
roccoblues committed Nov 13, 2023
1 parent ab994b1 commit 49ad73c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
46 changes: 23 additions & 23 deletions config/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)

bool result = true;

struct Buffer value = buf_make(256);
struct Buffer initial = buf_make(256);
struct Buffer tmp = buf_make(256);
struct Buffer *value = buf_pool_get();
struct Buffer *initial = buf_pool_get();
struct Buffer *tmp = buf_pool_get();

for (size_t i = 0; he_list[i]; i++)
{
buf_reset(&value);
buf_reset(&initial);
buf_reset(value);
buf_reset(initial);
he = he_list[i];
const int type = DTYPE(he->type);

Expand All @@ -201,7 +201,7 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
if ((flags & CS_DUMP_ONLY_CHANGED) || !(flags & CS_DUMP_HIDE_VALUE) ||
(flags & CS_DUMP_SHOW_DEFAULTS))
{
int rc = cs_he_string_get(cs, he, &value);
int rc = cs_he_string_get(cs, he, value);
if (CSR_RESULT(rc) != CSR_SUCCESS)
{
result = false; /* LCOV_EXCL_LINE */
Expand All @@ -210,54 +210,54 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)

const struct ConfigDef *cdef = he->data;
if ((type == DT_STRING) && IS_SENSITIVE(cdef->type) &&
(flags & CS_DUMP_HIDE_SENSITIVE) && !buf_is_empty(&value))
(flags & CS_DUMP_HIDE_SENSITIVE) && !buf_is_empty(value))
{
buf_reset(&value);
buf_addstr(&value, "***");
buf_reset(value);
buf_addstr(value, "***");
}

if (((type == DT_PATH) || IS_MAILBOX(he->type)) && (value.data[0] == '/'))
mutt_pretty_mailbox(value.data, value.dsize);
if (((type == DT_PATH) || IS_MAILBOX(he->type)) && (value->data[0] == '/'))
mutt_pretty_mailbox(value->data, value->dsize);

if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
(type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
{
buf_reset(&tmp);
pretty_var(value.data, &tmp);
buf_strcpy(&value, tmp.data);
buf_reset(tmp);
pretty_var(value->data, tmp);
buf_strcpy(value, tmp->data);
}
}

/* If necessary, get the default value */
if (flags & (CS_DUMP_ONLY_CHANGED | CS_DUMP_SHOW_DEFAULTS))
{
int rc = cs_he_initial_get(cs, he, &initial);
int rc = cs_he_initial_get(cs, he, initial);
if (CSR_RESULT(rc) != CSR_SUCCESS)
{
result = false; /* LCOV_EXCL_LINE */
break; /* LCOV_EXCL_LINE */
}

if (((type == DT_PATH) || IS_MAILBOX(he->type)) && !(he->type & DT_MAILBOX))
mutt_pretty_mailbox(initial.data, initial.dsize);
mutt_pretty_mailbox(initial->data, initial->dsize);

if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
(type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
{
buf_reset(&tmp);
pretty_var(initial.data, &tmp);
buf_strcpy(&initial, tmp.data);
buf_reset(tmp);
pretty_var(initial->data, tmp);
buf_strcpy(initial, tmp->data);
}
}
}

dump_config_neo(cs, he, &value, &initial, flags, fp);
dump_config_neo(cs, he, value, initial, flags, fp);
}

FREE(&he_list);
buf_dealloc(&value);
buf_dealloc(&initial);
buf_dealloc(&tmp);
buf_pool_release(&value);
buf_pool_release(&initial);
buf_pool_release(&tmp);

return result;
}
8 changes: 4 additions & 4 deletions config/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,21 @@ bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[],
if (!cs || !vars)
return false;

struct Buffer err = buf_make(0);
struct Buffer *err = buf_pool_get();

bool rc = true;

for (size_t i = 0; vars[i].name; i++)
{
vars[i].type |= flags;
if (!cs_register_variable(cs, &vars[i], &err))
if (!cs_register_variable(cs, &vars[i], err))
{
mutt_debug(LL_DEBUG1, "%s\n", buf_string(&err));
mutt_debug(LL_DEBUG1, "%s\n", buf_string(err));
rc = false;
}
}

buf_dealloc(&err);
buf_pool_release(&err);
return rc;
}

Expand Down

0 comments on commit 49ad73c

Please sign in to comment.