From 9b74cedb20beccd9b4f270f3c8ce6ba712e385a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 24 Aug 2019 11:33:13 +0200 Subject: [PATCH] vt: clear CSI parameters lazily The CLEAR action is so common, that explicitly clearing the entire params array, which is kind of big, is too slow. Clear it lazily instead. Meaning, we only set 'idx' (count) to 0 in CLEAR. Then whenever we parse a parameter, clear the value and sub parameters. --- vt.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vt.c b/vt.c index e227bef8..d83384df 100644 --- a/vt.c +++ b/vt.c @@ -858,7 +858,7 @@ action(struct terminal *term, enum action _action, uint8_t c) break; case ACTION_CLEAR: - memset(&term->vt.params, 0, sizeof(term->vt.params)); + term->vt.params.idx = 0; term->vt.private[0] = 0; term->vt.private[1] = 0; term->vt.osc.idx = 0; @@ -874,13 +874,21 @@ action(struct terminal *term, enum action _action, uint8_t c) break; case ACTION_PARAM: - if (term->vt.params.idx == 0) + if (term->vt.params.idx == 0) { term->vt.params.idx = 1; + term->vt.params.v[0].value = 0; + term->vt.params.v[0].sub.idx = 0; + } if (c == ';') { term->vt.params.idx++; + term->vt.params.v[term->vt.params.idx - 1].value = 0; + term->vt.params.v[term->vt.params.idx - 1].sub.idx = 0; + term->vt.params.v[term->vt.params.idx - 1].sub.value[0] = 0; } else if (c == ':') { - term->vt.params.v[term->vt.params.idx - 1].sub.idx++; + struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1]; + param->sub.idx++; + param->sub.value[param->sub.idx] = 0; } else { assert(term->vt.params.idx >= 0); struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1];