degesch: optimize prompt changes

We used to do lots of unnecessary redisplays.
This commit is contained in:
Přemysl Eric Janouch 2015-11-22 17:49:27 +01:00
parent 385de6f4fe
commit f69edd6606

View File

@ -5055,6 +5055,16 @@ make_prompt (struct app_context *ctx, struct str *output)
str_append_c (output, ']');
}
static void
input_maybe_set_prompt (struct input *self, char *new_prompt)
{
// Redisplay can be an expensive operation
if (self->prompt && !strcmp (new_prompt, self->prompt))
free (new_prompt);
else
input_set_prompt (self, new_prompt);
}
static void
refresh_prompt (struct app_context *ctx)
{
@ -5070,7 +5080,7 @@ refresh_prompt (struct app_context *ctx)
if (have_attributes)
{
// XXX: to be completely correct, we should use tputs, but we cannot
input_set_prompt (&ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c",
input_maybe_set_prompt (&ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c",
INPUT_START_IGNORE, ctx->attrs[ATTR_PROMPT],
INPUT_END_IGNORE,
localized,
@ -5079,7 +5089,7 @@ refresh_prompt (struct app_context *ctx)
free (localized);
}
else
input_set_prompt (&ctx->input, localized);
input_maybe_set_prompt (&ctx->input, localized);
}
// --- Helpers -----------------------------------------------------------------