diff options
author | Adrian Thurston <thurston@colm.net> | 2018-06-25 12:37:36 +0700 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2018-06-25 12:37:36 +0700 |
commit | 2f3208e30df5be690f1a5acfbeaf94b723b73a41 (patch) | |
tree | df79f406112c3e4beb44a5a9bd44c7472e313e94 | |
parent | 2c3a53fcc12e2435cb8950c146c1f7fe63949b72 (diff) | |
download | colm-2f3208e30df5be690f1a5acfbeaf94b723b73a41.tar.gz |
stash the head when consuming a tree and pop it when undoing
-rw-r--r-- | src/input.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/input.c b/src/input.c index cd80d550..be86f8f0 100644 --- a/src/input.c +++ b/src/input.c @@ -942,14 +942,14 @@ static tree_t *stream_consume_tree( struct stream_impl_seq *is ) free( seq_buf ); } + assert( is->queue != 0 && ( is->queue->type == RUN_BUF_TOKEN_TYPE || is->queue->type == RUN_BUF_IGNORE_TYPE ) ); + if ( is->queue != 0 && (is->queue->type == RUN_BUF_TOKEN_TYPE || is->queue->type == RUN_BUF_IGNORE_TYPE) ) { struct seq_buf *seq_buf = input_stream_seq_pop_head( is ); - - /* FIXME: using runbufs here for this is a poor use of memory. */ + input_stream_stash_head( is, seq_buf ); tree_t *tree = seq_buf->tree; - free(seq_buf); return tree; } @@ -961,10 +961,9 @@ static void stream_undo_consume_tree( struct stream_impl_seq *is, tree_t *tree, /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of * data that can be pushed back to the inputStream. */ - struct seq_buf *new_buf = new_seq_buf( 0 ); - new_buf->type = ignore ? RUN_BUF_IGNORE_TYPE : RUN_BUF_TOKEN_TYPE; - new_buf->tree = tree; - input_stream_seq_prepend( is, new_buf ); + + struct seq_buf *b = input_stream_pop_stash( is ); + input_stream_seq_prepend( is, b ); } static struct LangEl *stream_consume_lang_el( struct stream_impl_seq *is, long *bind_id, |