degesch: lesser heap fragmentation

This commit is contained in:
Přemysl Eric Janouch 2016-01-17 22:15:48 +01:00
parent 6db40c4503
commit 588a696c68
1 changed files with 7 additions and 11 deletions

View File

@ -1045,22 +1045,21 @@ struct buffer_line
int flags; ///< Flags
time_t when; ///< Time of the event
struct formatter *formatter; ///< Line data
struct formatter formatter; ///< Line data
};
struct buffer_line *
buffer_line_new (void)
buffer_line_new (struct formatter *f)
{
struct buffer_line *self = xcalloc (1, sizeof *self);
self->formatter = *f;
return self;
}
static void
buffer_line_destroy (struct buffer_line *self)
{
if (self->formatter)
formatter_free (self->formatter);
free (self->formatter);
formatter_free (&self->formatter);
free (self);
}
@ -3052,7 +3051,7 @@ buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
if (flags & BUFFER_LINE_STATUS) formatter_add (f, " - ");
if (flags & BUFFER_LINE_ERROR) formatter_add (f, "#a=!=#r ", ATTR_ERROR);
formatter_add_from (f, line->formatter);
formatter_add_from (f, &line->formatter);
formatter_add (f, "\n");
formatter_flush (f, output, raw_attributes);
formatter_free (f);
@ -3142,14 +3141,11 @@ log_formatter (struct app_context *ctx,
if (!buffer)
buffer = ctx->global_buffer;
struct buffer_line *line = buffer_line_new ();
// Move the formatter inside
struct buffer_line *line = buffer_line_new (f);
line->flags = flags;
line->when = time (NULL);
// Move the formatter inside
line->formatter = xmalloc (sizeof *line->formatter);
*line->formatter = *f;
buffer_pop_excess_lines (ctx, buffer);
LIST_APPEND_WITH_TAIL (buffer->lines, buffer->lines_tail, line);
buffer->lines_count++;