diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-05-06 03:30:48 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-05-06 03:30:48 -0400 |
commit | 24cdab0ff9c4747a15f8d13acf8cca9d27cf296c (patch) | |
tree | ea27bdd041b7be90c61778c634cca3b9d06ff9e4 | |
parent | bfe9fca8c487d78c9602dd57ebe69c8ea5c6404a (diff) | |
download | runes-24cdab0ff9c4747a15f8d13acf8cca9d27cf296c.tar.gz runes-24cdab0ff9c4747a15f8d13acf8cca9d27cf296c.zip |
stop creating and destroying parser states all the time
-rw-r--r-- | src/screen.c | 14 | ||||
-rw-r--r-- | src/screen.h | 9 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/screen.c b/src/screen.c index 39c0b87..923f8ee 100644 --- a/src/screen.c +++ b/src/screen.c @@ -16,6 +16,7 @@ void runes_screen_init(RunesTerm *t) RunesScreen *scr = &t->scr; scr->grid = calloc(1, sizeof(struct runes_grid)); + runes_parser_yylex_init_extra(t, &scr->scanner); } void runes_screen_set_window_size(RunesTerm *t) @@ -80,21 +81,18 @@ void runes_screen_set_window_size(RunesTerm *t) void runes_screen_process_string(RunesTerm *t, char *buf, size_t len) { - YY_BUFFER_STATE state; - yyscan_t scanner; + RunesScreen *scr = &t->scr; int remaining; - runes_parser_yylex_init_extra(t, &scanner); - state = runes_parser_yy_scan_bytes(buf, len, scanner); - remaining = runes_parser_yylex(scanner); + scr->state = runes_parser_yy_scan_bytes(buf, len, scr->scanner); + remaining = runes_parser_yylex(scr->scanner); t->pty.remaininglen = remaining; if (t->pty.remaininglen) { memmove( t->pty.readbuf, &buf[len - t->pty.remaininglen], t->pty.remaininglen); } - runes_parser_yy_delete_buffer(state, scanner); - runes_parser_yylex_destroy(scanner); + runes_parser_yy_delete_buffer(scr->state, scr->scanner); } void runes_screen_audible_bell(RunesTerm *t) @@ -737,6 +735,8 @@ void runes_screen_cleanup(RunesTerm *t) free(scr->title); free(scr->icon_name); + + runes_parser_yylex_destroy(scr->scanner); } static void runes_screen_ensure_capacity(RunesTerm *t, int size) diff --git a/src/screen.h b/src/screen.h index 3132e8a..d08139b 100644 --- a/src/screen.h +++ b/src/screen.h @@ -72,6 +72,12 @@ struct runes_grid { struct runes_row *rows; }; +/* XXX including parser.h in a place which would be visible here breaks things, + * so we copy these defintions over here */ +typedef void* yyscan_t; +struct yy_buffer_state; +typedef struct yy_buffer_state *YY_BUFFER_STATE; + struct runes_screen { struct runes_grid *grid; struct runes_grid *alternate; @@ -83,6 +89,9 @@ struct runes_screen { struct runes_cell_attrs attrs; + yyscan_t scanner; + YY_BUFFER_STATE state; + unsigned char hide_cursor: 1; unsigned char application_keypad: 1; unsigned char application_cursor: 1; |