Skip to content

Commit

Permalink
Speed up drawing of printable ascii chars
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Nov 12, 2023
1 parent 84577a3 commit ce8d744
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
9 changes: 0 additions & 9 deletions kitty/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,6 @@ line_get_char(Line *self, index_type at) {
return ch;
}

void
line_set_printable_ascii_chars(Line *self, unsigned int at, const uint8_t *chars, unsigned num, GPUCell g, CPUCell cc) {
for (unsigned i = at; i < at + num; i++, chars++) {
cc.ch = *chars;
self->gpu_cells[i] = g;
self->cpu_cells[i] = cc;
}
}

void
line_set_char(Line *self, unsigned int at, uint32_t ch, unsigned int width, Cursor *cursor, hyperlink_id_type hyperlink_id) {
GPUCell *g = self->gpu_cells + at;
Expand Down
1 change: 0 additions & 1 deletion kitty/lineops.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void line_clear_text(Line *self, unsigned int at, unsigned int num, char_type ch
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
char_type line_get_char(Line *self, index_type at);
void line_set_char(Line *, unsigned int , uint32_t , unsigned int , Cursor *, hyperlink_id_type);
void line_set_printable_ascii_chars(Line *self, unsigned int at, const uint8_t *chars, unsigned num, GPUCell g, CPUCell cc);
void line_right_shift(Line *, unsigned int , unsigned int );
void line_add_combining_char(Line *, uint32_t , unsigned int );
index_type line_url_start_at(Line *self, index_type x);
Expand Down
13 changes: 10 additions & 3 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ screen_draw_printable_ascii(Screen *self, const uint8_t *chars, size_t num) {
screen_on_input(self);
self->last_graphic_char = chars[num-1];
self->is_dirty = true;
CPUCell cc = {.hyperlink_id=self->active_hyperlink_id};
const CPUCell cc = {.hyperlink_id=self->active_hyperlink_id};
GPUCell g = {.attrs=cursor_to_attrs(self->cursor, 1), .fg=self->cursor->fg & COL_MASK, .bg=self->cursor->bg & COL_MASK, .decoration_fg=self->cursor->decoration_fg & COL_MASK};
if (OPT(underline_hyperlinks) == UNDERLINE_ALWAYS && cc.hyperlink_id) {
g.decoration_fg = ((OPT(url_color) & COL_MASK) << 8) | 2;
Expand All @@ -671,8 +671,15 @@ screen_draw_printable_ascii(Screen *self, const uint8_t *chars, size_t num) {
#define fill_single_line(chars, num) { \
linebuf_init_line(self->linebuf, self->cursor->y); \
if (self->modes.mIRM) line_right_shift(self->linebuf->line, self->cursor->x, num); \
line_set_printable_ascii_chars(self->linebuf->line, self->cursor->x, chars, num, g, cc); \
self->cursor->x += num; \
const unsigned limit = self->cursor->x + num; \
const uint8_t *p = chars; \
GPUCell *gp = self->linebuf->line->gpu_cells; \
CPUCell *cp = self->linebuf->line->cpu_cells; \
for (; self->cursor->x < limit; self->cursor->x++, p++) { \
gp[self->cursor->x] = g; \
cp[self->cursor->x] = cc; \
cp[self->cursor->x].ch = *p; \
} \
if (selection_has_screen_line(&self->selections, self->cursor->y)) clear_selection(&self->selections); \
linebuf_mark_line_dirty(self->linebuf, self->cursor->y); \
}
Expand Down
11 changes: 7 additions & 4 deletions kitty/vt-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ _report_params(PyObject *dump_callback, id_type window_id, const char *name, int
#define REPORT_DRAW(ch) \
Py_XDECREF(PyObject_CallFunction(self->dump_callback, "KsC", self->window_id, "draw", ch)); PyErr_Clear();

#define REPORT_DRAW_ASCII(ch, sz) \
Py_XDECREF(PyObject_CallFunction(self->dump_callback, "Kss#", self->window_id, "draw", ch, (Py_ssize_t)sz)); PyErr_Clear();

#define REPORT_PARAMS(name, params, num, is_group, region) _report_params(self->dump_callback, self->window_id, name, params, num_params, is_group, region)

#define REPORT_OSC(name, string) \
Expand All @@ -110,6 +113,7 @@ _report_params(PyObject *dump_callback, id_type window_id, const char *name, int
#define REPORT_COMMAND(...)
#define REPORT_VA_COMMAND(...)
#define REPORT_DRAW(ch)
#define REPORT_DRAW_ASCII(ch, sz)
#define REPORT_PARAMS(...)
#define REPORT_OSC(name, string)
#define REPORT_OSC2(name, code, string)
Expand Down Expand Up @@ -272,10 +276,9 @@ dispatch_normal_mode_byte(PS *self, uint8_t ch) {

static void
dispatch_printable_ascii(PS *self, const size_t sz) {
for (const size_t limit = self->read.pos + sz; self->read.pos < limit; self->read.pos++) {
REPORT_DRAW(self->buf[self->read.pos]);
screen_draw(self->screen, self->buf[self->read.pos]);
}
REPORT_DRAW_ASCII(self->buf + self->read.pos, sz);
screen_draw_printable_ascii(self->screen, self->buf + self->read.pos, sz);
self->read.pos += sz;
}

static void
Expand Down

0 comments on commit ce8d744

Please sign in to comment.