Cache temporary string in the decoder, for better benchmark numbers.

pull/13171/head
Joshua Haberman 14 years ago
parent c358fff57f
commit bd1dfd397e
  1. 10
      stream/upb_decoder.c
  2. 3
      stream/upb_decoder.h

@ -247,7 +247,6 @@ void upb_decoder_run(upb_src *src, upb_status *status) {
// by external code (like when we dispatch a callback). We must be sure not
// to let its address escape this source file.
upb_dstate state = {NULL, (void*)0x1, 0, d->top->msgdef};
upb_string *str = NULL;
// TODO: handle UPB_SKIPSUBMSG
#define CHECK_FLOW(expr) if ((expr) == UPB_BREAK) { assert(!upb_ok(status)); goto err; }
@ -273,7 +272,6 @@ void upb_decoder_run(upb_src *src, upb_status *status) {
// Normal end-of-file.
upb_clearerr(status);
CHECK_FLOW(upb_dispatch_endmsg(&d->dispatcher));
upb_string_unref(str);
return;
} else {
if (status->code == UPB_EOF) {
@ -313,7 +311,7 @@ void upb_decoder_run(upb_src *src, upb_status *status) {
if (!f) {
if (tag.wire_type == UPB_WIRE_TYPE_DELIMITED)
CHECK(upb_decode_string(d, &val, &str, &state));
CHECK(upb_decode_string(d, &val, &d->tmp, &state));
CHECK_FLOW(upb_dispatch_unknownval(&d->dispatcher, tag.field_number, val));
} else if (!upb_check_type(tag.wire_type, f->type)) {
// TODO: put more details in this error msg.
@ -336,7 +334,7 @@ void upb_decoder_run(upb_src *src, upb_status *status) {
continue; // We have no value to dispatch.
case UPB_TYPE(STRING):
case UPB_TYPE(BYTES):
CHECK(upb_decode_string(d, &val, &str, &state));
CHECK(upb_decode_string(d, &val, &d->tmp, &state));
break;
case UPB_TYPE(SINT32):
upb_value_setint32(&val, upb_zzdec_32(upb_value_getint32(val)));
@ -354,7 +352,6 @@ void upb_decoder_run(upb_src *src, upb_status *status) {
}
err:
upb_string_unref(str);
if (upb_ok(status)) {
upb_seterr(status, UPB_ERROR, "Callback returned UPB_BREAK");
}
@ -381,6 +378,7 @@ void upb_decoder_init(upb_decoder *d, upb_msgdef *msgdef) {
d->toplevel_msgdef = msgdef;
d->limit = &d->stack[UPB_MAX_NESTING];
d->buf = NULL;
d->tmp = NULL;
}
void upb_decoder_reset(upb_decoder *d, upb_bytesrc *bytesrc) {
@ -389,11 +387,11 @@ void upb_decoder_reset(upb_decoder *d, upb_bytesrc *bytesrc) {
d->top->msgdef = d->toplevel_msgdef;
// Never want to end top-level message, so treat it like a group.
d->top->end_offset = UPB_GROUP_END_OFFSET;
upb_string_recycle(&d->buf);
}
void upb_decoder_uninit(upb_decoder *d) {
upb_string_unref(d->buf);
upb_string_unref(d->tmp);
}
upb_src *upb_decoder_src(upb_decoder *d) { return &d->src; }

@ -53,6 +53,9 @@ struct _upb_decoder {
// Current input buffer.
upb_string *buf;
// Temporary string for passing to callbacks.
upb_string *tmp;
// The offset within the overall stream represented by the *beginning* of buf.
size_t buf_stream_offset;
};

Loading…
Cancel
Save