From f69edd6606dc7ed720a2328cc434e3f28a09e951 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 22 Nov 2015 17:49:27 +0100 Subject: degesch: optimize prompt changes We used to do lots of unnecessary redisplays. --- degesch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/degesch.c b/degesch.c index 436e9eb..f4deab3 100644 --- a/degesch.c +++ b/degesch.c @@ -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 ----------------------------------------------------------------- -- cgit v1.2.3-70-g09d2