summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-10-16 09:46:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-10-16 09:46:07 +0000
commit8ef801b40ce0be20ae55676d560d4040c5f1edf0 (patch)
tree2ab6df24e5d26b5762c634ca673d6ba0e84160f9 /editors
parent7960ea8918c601c6f5c35f50a118a51ca0fbea84 (diff)
downloadbusybox-w32-8ef801b40ce0be20ae55676d560d4040c5f1edf0.tar.gz
busybox-w32-8ef801b40ce0be20ae55676d560d4040c5f1edf0.tar.bz2
busybox-w32-8ef801b40ce0be20ae55676d560d4040c5f1edf0.zip
vi: a few trivial optimizations to keyboard reading code; bump timeout to 50s.
function old new delta edit_file 901 912 +11 count_lines 74 72 -2 readit 306 289 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-19) Total: -8 bytes
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/editors/vi.c b/editors/vi.c
index a75735945..7b213dfb3 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -629,12 +629,12 @@ static void edit_file(char *fn)
629 } 629 }
630#endif 630#endif
631 do_cmd(c); // execute the user command 631 do_cmd(c); // execute the user command
632 // 632
633 // poll to see if there is input already waiting. if we are 633 // poll to see if there is input already waiting. if we are
634 // not able to display output fast enough to keep up, skip 634 // not able to display output fast enough to keep up, skip
635 // the display update until we catch up with input. 635 // the display update until we catch up with input.
636 if (mysleep(0) == 0) { 636 if (!chars_to_parse && mysleep(0) == 0) {
637 // no input pending- so update output 637 // no input pending - so update output
638 refresh(FALSE); 638 refresh(FALSE);
639 show_status_line(); 639 show_status_line();
640 } 640 }
@@ -2243,8 +2243,10 @@ static char readit(void) // read (maybe cursor) key from stdin
2243 2243
2244 n = chars_to_parse; 2244 n = chars_to_parse;
2245 if (n == 0) { 2245 if (n == 0) {
2246 // If no data, block waiting for input. 2246 // If no data, block waiting for input
2247 n = safe_read(0, readbuffer, 1); 2247 // (can't read more than minimal ESC sequence -
2248 // see "n = 0" below).
2249 n = safe_read(0, readbuffer, 3);
2248 if (n <= 0) { 2250 if (n <= 0) {
2249 error: 2251 error:
2250 go_bottom_and_clear_to_eol(); 2252 go_bottom_and_clear_to_eol();
@@ -2264,25 +2266,29 @@ static char readit(void) // read (maybe cursor) key from stdin
2264 // If it's an escape sequence, loop through known matches. 2266 // If it's an escape sequence, loop through known matches.
2265 if (c == 27) { 2267 if (c == 27) {
2266 const struct esc_cmds *eindex; 2268 const struct esc_cmds *eindex;
2269 struct pollfd pfd;
2267 2270
2271 pfd.fd = STDIN_FILENO;
2272 pfd.events = POLLIN;
2268 for (eindex = esccmds; eindex < esccmds + ARRAY_SIZE(esccmds); eindex++) { 2273 for (eindex = esccmds; eindex < esccmds + ARRAY_SIZE(esccmds); eindex++) {
2269 // n - position in seq to read 2274 // n - position in sequence we did not read yet
2270 int i = 0; // position in seq to compare 2275 int i = 0; // position in sequence to compare
2271 int cnt = strnlen(eindex->seq, 4);
2272 2276
2273 // Loop through chars in this sequence. 2277 // Loop through chars in this sequence
2274 for (;;) { 2278 for (;;) {
2275 // We've matched this escape sequence up to [i-1] 2279 // So far escape sequence matches up to [i-1]
2276 if (n <= i) { 2280 if (n <= i) {
2277 // Need more chars, read another one if it wouldn't block. 2281 // Need more chars, read another one if it wouldn't block.
2278 // (Note that escape sequences come in as a unit, 2282 // (Note that escape sequences come in as a unit,
2279 // so if we would block it's not really an escape sequence.) 2283 // so if we would block it's not really an escape sequence.)
2280 struct pollfd pfd; 2284
2281 pfd.fd = 0; 2285 // Timeout is needed to reconnect escape sequences
2282 pfd.events = POLLIN; 2286 // split up by transmission over a serial console.
2283 // Timeout is needed to reconnect escape sequences split 2287 // Even though inter-char delay on 1200 baud is <10ms,
2284 // up by transmission over a serial console. 2288 // process scheduling can enlarge it arbitrarily,
2285 if (safe_poll(&pfd, 1, 25)) { 2289 // on both send and receive sides.
2290 // Erring on the safe side - 5 timer ticks on 100 HZ.
2291 if (safe_poll(&pfd, 1, 50)) {
2286 if (safe_read(0, readbuffer + n, 1) <= 0) 2292 if (safe_read(0, readbuffer + n, 1) <= 0)
2287 goto error; 2293 goto error;
2288 n++; 2294 n++;
@@ -2296,9 +2302,14 @@ static char readit(void) // read (maybe cursor) key from stdin
2296 } 2302 }
2297 if (readbuffer[i] != eindex->seq[i]) 2303 if (readbuffer[i] != eindex->seq[i])
2298 break; // try next seq 2304 break; // try next seq
2299 if (++i == cnt) { // entire seq matched 2305 i++;
2306 if (i == 4 || !eindex->seq[i]) { // entire seq matched
2300 c = eindex->val; 2307 c = eindex->val;
2301 n = 0; 2308 n = 0;
2309 // n -= i; memmove(...);
2310 // would be more correct,
2311 // but we never read ahead that much,
2312 // and n == i here.
2302 goto loop_out; 2313 goto loop_out;
2303 } 2314 }
2304 } 2315 }
@@ -2306,7 +2317,7 @@ static char readit(void) // read (maybe cursor) key from stdin
2306 // We did not find matching sequence, it was a bare ESC. 2317 // We did not find matching sequence, it was a bare ESC.
2307 // We possibly read and stored more input in readbuffer by now. 2318 // We possibly read and stored more input in readbuffer by now.
2308 } 2319 }
2309loop_out: 2320 loop_out:
2310 2321
2311 chars_to_parse = n; 2322 chars_to_parse = n;
2312 return c; 2323 return c;