Skip to content

Commit

Permalink
drop cell_blank from View
Browse files Browse the repository at this point in the history
No need for this to be stored in every View since its just a never
modified cell with a space.

Also delete the cell_unused global since all it does is provide a
0 initialized Cell.
  • Loading branch information
rnpnr committed May 24, 2024
1 parent e629d49 commit 4d38c3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
20 changes: 7 additions & 13 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ static const SyntaxSymbol symbols_default[] = {
[SYNTAX_SYMBOL_EOF] = { "~" },
};

static Cell cell_unused;

static Cell cell_blank = { .width = 0, .len = 0, .data = " ", };

/* move visible viewport n-lines up/down, redraws the view but does not change
* cursor position which becomes invalid and should be corrected by calling
Expand Down Expand Up @@ -203,7 +202,7 @@ static void view_clear(View *view) {
view->wrapcol = 0;
view->prevch_breakat = false;
if (view->ui)
ui_window_style_set(view->ui, &view->cell_blank, UI_STYLE_DEFAULT);
ui_window_style_set(view->ui, &cell_blank, UI_STYLE_DEFAULT);
}

static int view_max_text_width(const View *view) {
Expand Down Expand Up @@ -238,7 +237,7 @@ static void view_wrap_line(View *view) {
wrapped_line->width -= wrapped_line->cells[i].width;
wrapped_line->len -= wrapped_line->cells[i].len;
}
wrapped_line->cells[i] = view->cell_blank;
wrapped_line->cells[i] = cell_blank;
}
}

Expand All @@ -259,7 +258,7 @@ static bool view_add_cell(View *view, const Cell *cell) {
view->line->cells[view->col++] = *cell;
/* set cells of a character which uses multiple columns */
for (int i = 1; i < cell->width; i++)
view->line->cells[view->col++] = cell_unused;
view->line->cells[view->col++] = (Cell){0};
return true;
}

Expand Down Expand Up @@ -308,7 +307,7 @@ static bool view_addch(View *view, Cell *cell) {
view->wrapcol = view->col;
}
view->prevch_breakat = ch_breakat;
cell->style = view->cell_blank.style;
cell->style = cell_blank.style;

unsigned char ch = (unsigned char)cell->data[0];
switch (ch) {
Expand Down Expand Up @@ -484,7 +483,7 @@ void view_draw(View *view) {
/* clear remaining of line, important to show cursor at end of file */
if (view->line) {
for (int x = view->col; x < view->width; x++)
view->line->cells[x] = view->cell_blank;
view->line->cells[x] = cell_blank;
}

/* resync position of cursors within visible area */
Expand All @@ -506,7 +505,7 @@ bool view_update(View *view) {
return false;
for (Line *l = view->lastline->next; l; l = l->next) {
for (int x = 0; x < view->width; x++)
l->cells[x] = view->cell_blank;
l->cells[x] = cell_blank;
}
view->need_update = false;
return true;
Expand Down Expand Up @@ -567,11 +566,6 @@ bool view_init(View *view, Text *text) {
view->tabwidth = 8;
view->breakat = strdup("");
view->wrapcolumn = 0;
view->cell_blank = (Cell) {
.width = 0,
.len = 0,
.data = " ",
};
view_options_set(view, 0);

if (!view->breakat ||
Expand Down
1 change: 0 additions & 1 deletion view.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ typedef struct View {
Text *text; /* underlying text management */
char *textbuf; /* scratch buffer used for drawing */
UiWin *ui; /* corresponding ui window */
Cell cell_blank; /* used for empty/blank cells */
int width, height; /* size of display area */
size_t start, end; /* currently displayed area [start, end] in bytes from the start of the file */
size_t start_last; /* previously used start of visible area, used to update the mark */
Expand Down

0 comments on commit 4d38c3a

Please sign in to comment.