From dedb8b7ebf103b09c78e5f088f3cc7038b5adc5c Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Sat, 4 Jan 2025 18:04:31 -0700 Subject: [PATCH] ui: remove useless memcpy call 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. --- ui-terminal.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ui-terminal.c b/ui-terminal.c index 6e78d32d2..e16e90fc3 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -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) {