diff options
author | Joshua Haberman <joshua@reverberate.org> | 2010-07-24 18:18:09 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2010-07-24 18:18:09 -0700 |
commit | 2a617bf12c8e1f7f689e3767bf7e4582d76c4f39 (patch) | |
tree | 2b4a9af39d25cc7aabf755c2527560d2c675d1d7 | |
parent | 372c8f0487a666c3fb36edc18accba0fba9a2680 (diff) |
Optimizations and bugfix to benchmark.
-rw-r--r-- | benchmarks/parsestream.upb_table.c | 5 | ||||
-rw-r--r-- | stream/upb_decoder.c | 23 |
2 files changed, 18 insertions, 10 deletions
diff --git a/benchmarks/parsestream.upb_table.c b/benchmarks/parsestream.upb_table.c index 1e18119..16979b0 100644 --- a/benchmarks/parsestream.upb_table.c +++ b/benchmarks/parsestream.upb_table.c @@ -85,15 +85,14 @@ static size_t run(int i) upb_decoder_reset(decoder, upb_stringsrc_bytesrc(stringsrc)); upb_src *src = upb_decoder_src(decoder); upb_fielddef *f; - upb_string *str = NULL; int depth = 0; while(1) { - while((f = upb_src_getdef(src)) != NULL) { + while(!upb_src_eof(src) && (f = upb_src_getdef(src)) != NULL) { if(upb_issubmsg(f)) { upb_src_startmsg(src); ++depth; } else if(upb_isstring(f)) { - tmp_str = upb_string_tryrecycle(str); + tmp_str = upb_string_tryrecycle(tmp_str); upb_src_getstr(src, tmp_str); } else { // Primitive type. diff --git a/stream/upb_decoder.c b/stream/upb_decoder.c index 46cfb3f..7591f78 100644 --- a/stream/upb_decoder.c +++ b/stream/upb_decoder.c @@ -177,6 +177,12 @@ static bool upb_decoder_consume(upb_decoder *d, uint32_t bytes) memmove(d->tmpbuf, d->tmpbuf + bytes, -d->buf_offset); } assert(d->buf_bytesleft >= 0); + + // Detect end-of-submessage. + if(upb_decoder_offset(d) >= d->top->end_offset) { + d->src.eof = true; + } + return true; } @@ -187,6 +193,12 @@ static bool upb_decoder_skipbytes(upb_decoder *d, int32_t bytes) while(d->buf_bytesleft < 0) { if(!upb_decoder_nextbuf(d)) return false; } + + // Detect end-of-submessage. + if(upb_decoder_offset(d) >= d->top->end_offset) { + d->src.eof = true; + } + return true; } @@ -311,12 +323,7 @@ bool upb_decoder_skipval(upb_decoder *d); upb_fielddef *upb_decoder_getdef(upb_decoder *d) { - // Detect end-of-submessage. - if(upb_decoder_offset(d) >= d->top->end_offset) { - d->src.eof = true; - return NULL; - } - + if (d->src.eof) return NULL; // Handles the packed field case. if(d->field) { return d->field; @@ -481,7 +488,8 @@ bool upb_decoder_endmsg(upb_decoder *d) { else upb_decoder_skipbytes(d, d->top->end_offset - upb_decoder_offset(d)); } - d->src.eof = false; + // Detect end-of-submessage. + d->src.eof = upb_decoder_offset(d) >= d->top->end_offset; return true; } else { return false; @@ -571,6 +579,7 @@ void upb_decoder_reset(upb_decoder *d, upb_bytesrc *bytesrc) // indefinitely), so we set the end offset as high as possible, but not equal // to UINT32_MAX so it doesn't equal UPB_GROUP_END_OFFSET. d->top->end_offset = UINT32_MAX - 1; + d->src.eof = false; d->bytesrc = bytesrc; d->field = NULL; d->buf = NULL; |