vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 5c5d0b2c7005906e98173c98cd8ce1d4b3e7576c parent d403e59d17fc828df8f7aada666800e6e11fdae5 Author: Randy Palamar <randy@rnpnr.xyz> Date: Sat, 4 Jan 2025 18:04:31 -0700 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. Diffstat:
| M | ui-terminal.c | | | 20 | +++++++++----------- |
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git 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) {