Optimizations and bugfix to benchmark.

pull/13171/head
Joshua Haberman 15 years ago
parent 372c8f0487
commit 2a617bf12c
  1. 5
      benchmarks/parsestream.upb_table.c
  2. 23
      stream/upb_decoder.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.

@ -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;

Loading…
Cancel
Save