Skip to content

Commit

Permalink
ui: remove useless memcpy call
Browse files Browse the repository at this point in the history
If the compiler wants to use memcpy to move 12 bytes it can inline
the call itself otherwise we should just write the simple thing.
  • Loading branch information
rnpnr committed Jan 5, 2025
1 parent 8a14a81 commit dedb8b7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ui-terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,27 @@ static void ui_window_draw(Win *win) {
snprintf(buf, sizeof buf, "%*zu ", sidebar_width-1, number);
}
ui_draw_string(ui, x, y, buf, win,
(l->lineno == cursor_lineno) ? UI_STYLE_LINENUMBER_CURSOR : UI_STYLE_LINENUMBER);
(l->lineno == cursor_lineno) ? UI_STYLE_LINENUMBER_CURSOR :
UI_STYLE_LINENUMBER);
prev_lineno = l->lineno;
}
debug("draw-window: [%d][%d] ... cells[%d][%d]\n", y, x+sidebar_width, y, view_width);
memcpy(&cells[x+sidebar_width], l->cells, sizeof(Cell) * view_width);
memcpy(cells + x + sidebar_width, l->cells, sizeof(Cell) * view_width);
cells += ui->width;
}
}

void ui_window_style_set(Win *win, Cell *cell, enum UiStyle id) {
Ui *tui = &win->vis->ui;
CellStyle set, style = tui->styles[win->id * UI_STYLE_MAX + id];
CellStyle set = tui->styles[win->id * UI_STYLE_MAX + id];

if (id == UI_STYLE_DEFAULT) {
memcpy(&cell->style, &style, sizeof(CellStyle));
return;
if (id != UI_STYLE_DEFAULT) {
set.fg = is_default_fg(set.fg)? cell->style.fg : set.fg;
set.bg = is_default_bg(set.bg)? cell->style.bg : set.bg;
set.attr = cell->style.attr | set.attr;
}

set.fg = is_default_fg(style.fg)? cell->style.fg : style.fg;
set.bg = is_default_bg(style.bg)? cell->style.bg : style.bg;
set.attr = cell->style.attr | style.attr;

memcpy(&cell->style, &set, sizeof(CellStyle));
cell->style = set;
}

bool ui_window_style_set_pos(Win *win, int x, int y, enum UiStyle id) {
Expand Down

0 comments on commit dedb8b7

Please sign in to comment.