From 4dd09ba89d12807d2de1f415e88a6ce8d5f01ecb Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Sun, 16 Aug 2015 18:01:06 +0000 Subject: [PATCH] search: 10x speed improvement on large files - do_center_window used to be very inefficient when invoked with point at a great distance from the current window. This was slowing down successful searches on large files by a factor of 10 or more. --- qe.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qe.c b/qe.c index 869992b..a0f06f7 100644 --- a/qe.c +++ b/qe.c @@ -1166,8 +1166,14 @@ void do_center_cursor(EditState *s) if (!s->mode->text_display) return; - if (s->offset < s->offset_top) { - int offset_top = s->offset_top; + if (s->offset < s->offset_top + || (s->offset_bottom >= 0 && s->offset >= s->offset_bottom)) { + /* if point is outside the current window, first move the + * window to start at the line with point. This significantly + * speeds up get_cursor_pos() on large files, except for the + * pathological case of huge lines. + */ + int offset_top = s->offset; eb_prevc(s->b, offset_top, &offset_top); s->offset_top = s->mode->text_backward_offset(s, offset_top); }