diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-02-02 23:10:43 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-02-12 14:20:15 +0100 |
| commit | b4399ffbb402943e1972a9ed04b3ddb3fa6c6cfe (patch) | |
| tree | 4782b5eb06b24e85faef98116117ac5b65a40229 | |
| parent | 78f1da727768cc398a09939fdb8d325fdcdca863 (diff) | |
| download | vis-b4399ffbb402943e1972a9ed04b3ddb3fa6c6cfe.tar.gz vis-b4399ffbb402943e1972a9ed04b3ddb3fa6c6cfe.tar.xz | |
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
| -rw-r--r-- | ui-curses.c | 17 | ||||
| -rw-r--r-- | ui.h | 1 | ||||
| -rw-r--r-- | view.c | 10 | ||||
| -rw-r--r-- | vis.c | 11 |
4 files changed, 31 insertions, 8 deletions
diff --git a/ui-curses.c b/ui-curses.c index 671fa61..1bc145a 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -619,7 +619,7 @@ static bool ui_window_draw_sidebar(UiCursesWin *win) { if (win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE) { mvwprintw(win->winside, i, 0, "%*u", sidebar_width-1, l->lineno); } else if (win->options & UI_OPTION_LINE_NUMBERS_RELATIVE) { - size_t rel = l->lineno; + size_t rel = (win->options & UI_OPTION_LARGE_FILE) ? 0 : l->lineno; if (l->lineno > cursor_lineno) rel = l->lineno - cursor_lineno; else if (l->lineno < cursor_lineno) @@ -643,7 +643,6 @@ static void ui_window_draw_status(UiWin *w) { bool focused = uic->selwin == win; const char *filename = vis_file_name(win->file); const char *status = vis_mode_status(vis); - CursorPos pos = view_cursor_getpos(win->view); wattrset(win->winstatus, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->winstatus, 0, 0, ' ', win->width); mvwprintw(win->winstatus, 0, 0, "%s %s %s %s", @@ -651,11 +650,15 @@ static void ui_window_draw_status(UiWin *w) { filename ? filename : "[No Name]", text_modified(vis_file_text(win->file)) ? "[+]" : "", vis_macro_recording(vis) ? "recording": ""); - char buf[win->width + 1]; - int len = snprintf(buf, win->width, "%zd, %zd", pos.line, pos.col); - if (len > 0) { - buf[len] = '\0'; - mvwaddstr(win->winstatus, 0, win->width - len - 1, buf); + + if (!(win->options & UI_OPTION_LARGE_FILE)) { + CursorPos pos = view_cursor_getpos(win->view); + char buf[win->width + 1]; + int len = snprintf(buf, win->width, "%zd, %zd", pos.line, pos.col); + if (len > 0) { + buf[len] = '\0'; + mvwaddstr(win->winstatus, 0, win->width - len - 1, buf); + } } } @@ -25,6 +25,7 @@ enum UiOption { UI_OPTION_CURSOR_LINE = 1 << 7, UI_OPTION_STATUSBAR = 1 << 8, UI_OPTION_ONELINE = 1 << 9, + UI_OPTION_LARGE_FILE = 1 << 10, }; enum UiStyles { @@ -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); } @@ -43,6 +43,9 @@ #include "util.h" #include "vis-core.h" +/* enable large file optimization for files larger than: */ +#define LARGE_FILE (1 << 25) + static Macro *macro_get(Vis *vis, enum VisMacro m); static void macro_replay(Vis *vis, const Macro *macro); @@ -180,6 +183,14 @@ Win *window_new_file(Vis *vis, File *file) { } file->refcount++; view_tabwidth_set(win->view, vis->tabwidth); + + if (text_size(file->text) > LARGE_FILE) { + enum UiOption opt = view_options_get(win->view); + opt |= UI_OPTION_LARGE_FILE; + opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; + view_options_set(win->view, opt); + } + if (vis->windows) vis->windows->prev = win; win->next = vis->windows; |
