lt

simple terminal emulator
Log | Files | Refs | git clone https://git.ne02ptzero.me/git/lt

commit df848edc86bb7f9d50cd4d4a88a98b6c2c754792
parent 5c65c4f7e348f53bfbcbdb3346af51a50e9e5409
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  5 Jun 2018 18:59:07 +0200

FIX: Change BUF_SIZE from 1 to 2048 for better performance

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
Mx.c | 61+++++++++++++++++++++++++++++++++----------------------------
1 file changed, 33 insertions(+), 28 deletions(-)

diff --git a/x.c b/x.c @@ -93,39 +93,44 @@ static void term_redraw(term_t *term) XSync(term->__dsp, False); } -static void term_buf(term_t *term, char *buf, bool *just_wrapped) +static void term_buf(term_t *term, char *buf, size_t size) { - if (*buf == '\r') - term->__x = 0; - else + static bool just_wrapped = false; + + for (size_t i = 0; i < size; i++) { - if (*buf != '\n') + if (buf[i] == '\r') + term->__x = 0; + else { - term->buf[term->__y * term->cols + term->__x] = *buf; - term->__x++; + if (buf[i] != '\n') + { + term->buf[term->__y * term->cols + term->__x] = buf[i]; + term->__x++; - if (term->__x >= term->cols) + if (term->__x >= term->cols) + { + term->__x = 0; + term->__y++; + just_wrapped = true; + } + else + just_wrapped = false; + } + else if (!just_wrapped) { - term->__x = 0; term->__y++; - *just_wrapped = true; + just_wrapped = false; } - else - *just_wrapped = false; - } - else if (!*just_wrapped) - { - term->__y++; - *just_wrapped = false; - } - if (term->__y >= term->rows) - { - memmove(term->buf, &term->buf[term->cols], term->cols * (term->rows - 1)); - term->__y = term->rows - 1; + if (term->__y >= term->rows) + { + memmove(term->buf, &term->buf[term->cols], term->cols * (term->rows - 1)); + term->__y = term->rows - 1; - for (uint32_t i = 0; i < term->cols; i++) - term->buf[term->__y * term->cols + i] = 0; + for (uint32_t i = 0; i < term->cols; i++) + term->buf[term->__y * term->cols + i] = 0; + } } } } @@ -140,14 +145,14 @@ static void term_key(term_t *term, XKeyEvent *ev) write(term->pty.master, buf, num); } -#define BUF_SIZE 1 +#define BUF_SIZE 2048 void term_run(term_t *term) { int maxfd; + size_t size; fd_set readable; XEvent ev; char buf[BUF_SIZE]; - bool just_wrapped = false; maxfd = MAX(term->pty.master, term->win.fd); @@ -161,8 +166,8 @@ void term_run(term_t *term) if (FD_ISSET(term->pty.master, &readable)) { - read(term->pty.master, buf, sizeof(buf)); - term_buf(term, buf, &just_wrapped); + size = read(term->pty.master, buf, sizeof(buf)); + term_buf(term, buf, size); term_redraw(term); }