From dd7957cd1ccfe8df9e3ef12c233c91e021f75d1b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 23 Dec 2020 14:19:58 -0500 Subject: dash: Cache the expanded prompt for editline Previously, the prompt would be expanded every time editline called the getprompt callback. I think the code may have been written assuming that editline only calls getprompt once per prompt, but it may actually call it many times, for instance every time you type backspace. This results not only in slower editing from expanding complex prompts repeatedly, it also consumes more and more stack memory each time getprompt is called. This can be seen by setting PS1 to some command substitution, typing many characters at the prompt, then holding backspace and observing memory usage. Thankfully all this stack memory is freed between prompts by the stackmark calls around el_gets. This change causes prompt expansion to always happen in the setprompt call, as it would when editline is disabled, and a cached copy of the prompt is saved for getprompt to return every time editline calls it. Since getprompt is no longer doing expansion, the stackmark calls surrounding el_gets can be removed. --- src/input.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/input.c') diff --git a/src/input.c b/src/input.c index 17544e7..4167bd1 100644 --- a/src/input.c +++ b/src/input.c @@ -152,12 +152,8 @@ retry: static const char *rl_cp; static int el_len; - if (rl_cp == NULL) { - struct stackmark smark; - pushstackmark(&smark, stackblocksize()); + if (rl_cp == NULL) rl_cp = el_gets(el, &el_len); - popstackmark(&smark); - } if (rl_cp == NULL) nr = 0; else { -- cgit 1.4.1