Skip to content

Commit

Permalink
vis: enable large file optimizations for files with long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed May 4, 2016
1 parent bab79b3 commit c5f1b4e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
14 changes: 11 additions & 3 deletions ui-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "ui-curses.h"
#include "vis.h"
#include "vis-core.h"
#include "text.h"
#include "util.h"
#include "text-util.h"
Expand Down Expand Up @@ -638,14 +639,14 @@ static void ui_window_draw_status(UiWin *w) {
UiCurses *uic = win->ui;
Vis *vis = uic->vis;
bool focused = uic->selwin == win;
const char *filename = vis_file_name(win->file);
const char *filename = win->file->name;
const char *status = vis_mode_status(vis);
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",
focused && status ? status : "",
filename ? filename : "[No Name]",
text_modified(vis_file_text(win->file)) ? "[+]" : "",
text_modified(win->file->text) ? "[+]" : "",
vis_macro_recording(vis) ? "recording": "");

char buf[4*32] = "", *msg = buf;
Expand All @@ -660,6 +661,8 @@ static void ui_window_draw_status(UiWin *w) {
Cursor *cur = view_cursors_primary_get(win->view);
size_t line = view_cursors_line(cur);
size_t col = view_cursors_col(cur);
if (col > UI_LARGE_FILE_LINE_SIZE)
win->options |= UI_OPTION_LARGE_FILE;
msg += sprintf(msg, "%zu, %zu", line, col);
}

Expand Down Expand Up @@ -740,7 +743,7 @@ static void ui_window_reload(UiWin *w, File *file) {
UiCursesWin *win = (UiCursesWin*)w;
win->file = file;
win->sidebar_width = 0;
view_reload(win->view, vis_file_text(file));
view_reload(win->view, file->text);
ui_window_draw(w);
}

Expand Down Expand Up @@ -1008,6 +1011,11 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file, enum UiOption option
win->next = uic->windows;
uic->windows = win;

if (text_size(file->text) > UI_LARGE_FILE_SIZE) {
options |= UI_OPTION_LARGE_FILE;
options &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE;
}

ui_window_options_set((UiWin*)win, options);

return &win->uiwin;
Expand Down
5 changes: 5 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <stdbool.h>
#include <stdarg.h>

/* enable large file optimization for files larger than: */
#define UI_LARGE_FILE_SIZE (1 << 25)
/* enable large file optimization fo files containing lines longer than: */
#define UI_LARGE_FILE_LINE_SIZE (1 << 16)

typedef struct Ui Ui;
typedef struct UiWin UiWin;

Expand Down
19 changes: 0 additions & 19 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include "vis-core.h"
#include "sam.h"

/* enable large file optimization for files larger than: */
#define LARGE_FILE (1 << 25)

static Macro *macro_get(Vis *vis, enum VisRegister);
static void macro_replay(Vis *vis, const Macro *macro);
static void vis_keys_process(Vis *vis);
Expand Down Expand Up @@ -170,13 +167,6 @@ 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;
Expand Down Expand Up @@ -1373,12 +1363,3 @@ View *vis_view(Vis *vis) {
Win *vis_window(Vis *vis) {
return vis->win;
}

Text *vis_file_text(File *file) {
return file->text;
}

const char *vis_file_name(File *file) {
return file->name;
}

2 changes: 0 additions & 2 deletions vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ Regex *vis_regex(Vis*, const char *pattern);
Text *vis_text(Vis*);
View *vis_view(Vis*);
Win *vis_window(Vis*);
Text *vis_file_text(File*);
const char *vis_file_name(File*);

bool vis_theme_load(Vis*, const char *name);

Expand Down

0 comments on commit c5f1b4e

Please sign in to comment.