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.
This commit is contained in:
Daniel Eklöf 2019-08-24 11:33:13 +02:00
parent dcf6d18872
commit 9b74cedb20
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

14
vt.c
View file

@ -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];