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.
This commit is contained in:
Charlie Gordon 2015-08-16 18:01:06 +00:00
commit 4dd09ba89d

10
qe.c
View file

@ -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);
}