summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-13 17:00:10 +0800
committerAdrian Thurston <thurston@colm.net>2018-07-13 17:00:10 +0800
commit24f1ce1025ab111c61ba7cd23120e0cbf9b92570 (patch)
tree6317b2de8135816864c053be68f2df958ab7caed /src
parent1c97b4e09f0b509ff69c8eb04339f754e73e02df (diff)
downloadcolm-24f1ce1025ab111c61ba7cd23120e0cbf9b92570.tar.gz
don't create an empty run buf every time we hit stream end
Diffstat (limited to 'src')
-rw-r--r--src/input.c20
-rw-r--r--src/stream.c17
2 files changed, 11 insertions, 26 deletions
diff --git a/src/input.c b/src/input.c
index 9d93fb8e..99e65ec5 100644
--- a/src/input.c
+++ b/src/input.c
@@ -550,13 +550,10 @@ static tree_t *input_undo_prepend_stream( struct colm_program *prg, struct input
return 0;
}
-#define OPTIM_APPEND
-
static void input_append_data( struct colm_program *prg, struct input_impl_seq *si, const char *data, long length )
{
debug( prg, REALM_INPUT, "input_append_data: stream %p append data length %d\n", si, length );
-#ifdef OPTIM_APPEND
if ( si->queue.tail == 0 || si->queue.tail->type != SB_ACCUM ) {
debug( prg, REALM_INPUT, "input_append_data: creating accum\n" );
@@ -571,25 +568,12 @@ static void input_append_data( struct colm_program *prg, struct input_impl_seq *
}
si->queue.tail->si->funcs->append_data( prg, si->queue.tail->si, data, length );
-
-#else
-
- struct stream_impl *sub_si = colm_impl_new_text( "<text>", data, length );
-
- struct seq_buf *new_buf = new_seq_buf();
- new_buf->type = SB_ACCUM;
- new_buf->si = sub_si;
- new_buf->own_si = 1;
-
- input_stream_seq_append( si, new_buf );
-#endif
}
static tree_t *input_undo_append_data( struct colm_program *prg, struct input_impl_seq *si, int length )
{
debug( prg, REALM_INPUT, "input_undo_append_data: stream %p undo append data length %d\n", si, length );
-#ifdef OPTIM_APPEND
while ( true ) {
struct seq_buf *buf = si->queue.tail;
@@ -619,10 +603,6 @@ static tree_t *input_undo_append_data( struct colm_program *prg, struct input_im
struct seq_buf *seq_buf = input_stream_seq_pop_tail( si );
free( seq_buf );
}
-#else
- struct seq_buf *seq_buf = input_stream_seq_pop_tail( si );
- free( seq_buf );
-#endif
return 0;
}
diff --git a/src/stream.c b/src/stream.c
index c2d416d9..8d913488 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -193,11 +193,14 @@ static int data_get_data( struct colm_program *prg, struct stream_impl_data *ss,
if ( buf == 0 ) {
/* Got through the in-mem buffers without copying anything. */
struct run_buf *run_buf = new_run_buf( 0 );
- si_data_push_tail( ss, run_buf );
int received = ss->funcs->get_data_source( prg, (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE );
- run_buf->length = received;
- if ( received == 0 )
+ if ( received == 0 ) {
+ free( run_buf );
break;
+ }
+
+ run_buf->length = received;
+ si_data_push_tail( ss, run_buf );
buf = run_buf;
}
@@ -241,12 +244,12 @@ int data_append_data( struct colm_program *prg, struct stream_impl_data *sid, co
{
struct run_buf *tail = sid->queue.tail;
if ( tail == 0 || length > (FSM_BUFSIZE - tail->length) ) {
- debug( prg, REALM_INPUT, "input_append_data: allocating run buf\n" );
+ debug( prg, REALM_INPUT, "data_append_data: allocating run buf\n" );
tail = new_run_buf( length );
si_data_push_tail( sid, tail );
}
- debug( prg, REALM_INPUT, "input_append_data: appending to "
+ debug( prg, REALM_INPUT, "data_append_data: appending to "
"accum tail, offset: %d, length: %d, dlen: %d\n",
tail->offset, tail->length, length );
@@ -371,13 +374,15 @@ static int data_get_parse_block( struct colm_program *prg, struct stream_impl_da
if ( buf == 0 ) {
/* Got through the in-mem buffers without copying anything. */
struct run_buf *run_buf = new_run_buf( 0 );
- si_data_push_tail( ss, run_buf );
int received = ss->funcs->get_data_source( prg, (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE );
if ( received == 0 ) {
+ free( run_buf );
ret = INPUT_EOD;
break;
}
+
run_buf->length = received;
+ si_data_push_tail( ss, run_buf );
int slen = received;
*pdp = run_buf->data;