From b4399ffbb402943e1972a9ed04b3ddb3fa6c6cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 2 Feb 2016 23:10:43 +0100 Subject: Improve large file support Disable absolute line numbers for large files (currently anything bigger than 32MiB). This speeds up moving around with for example nn% since no new lines need to be calculated. Of course movements like :nn will be unaffected. The optimizations can be disabled by explicitly enabling absolute line numbers as in :set number --- view.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'view.c') diff --git a/view.c b/view.c index 4182cc5..abbc3a5 100644 --- a/view.c +++ b/view.c @@ -86,6 +86,7 @@ struct View { lua_State *lua; /* lua state used for syntax highlighting */ char *lexer_name; bool need_update; /* whether view has been redrawn */ + bool large_file; /* optimize for displaying large files */ int colorcolumn; }; @@ -305,7 +306,7 @@ static void view_clear(View *view) { view->start_last = view->start; view->topline = view->lines; - view->topline->lineno = text_lineno_by_pos(view->text, view->start); + view->topline->lineno = view->large_file ? 1 : text_lineno_by_pos(view->text, view->start); view->lastline = view->topline; size_t line_size = sizeof(Line) + view->width*sizeof(Cell); @@ -1012,10 +1013,17 @@ void view_options_set(View *view, enum UiOption options) { [SYNTAX_SYMBOL_EOL] = UI_OPTION_SYMBOL_EOL, [SYNTAX_SYMBOL_EOF] = UI_OPTION_SYMBOL_EOF, }; + for (int i = 0; i < LENGTH(mapping); i++) { view->symbols[i] = (options & mapping[i]) ? &symbols_default[i] : &symbols_none[i]; } + + if (options & UI_OPTION_LINE_NUMBERS_ABSOLUTE) + options &= ~UI_OPTION_LARGE_FILE; + + view->large_file = (options & UI_OPTION_LARGE_FILE); + if (view->ui) view->ui->options_set(view->ui, options); } -- cgit v1.2.3