diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-02-09 12:19:45 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-02-09 12:19:45 -0800 |
commit | bd1dfd397e02546b4d5a45fac76f3fb1bf685172 (patch) | |
tree | b475ee851566b3e84f9d66ac335449d0b34649ad | |
parent | c358fff57f0cb52c16e67596d316c66b737d604f (diff) |
Cache temporary string in the decoder, for better benchmark numbers.
-rw-r--r-- | stream/upb_decoder.c | 10 | ||||
-rw-r--r-- | stream/upb_decoder.h | 3 |
2 files changed, 7 insertions, 6 deletions
diff --git a/stream/upb_decoder.c b/stream/upb_decoder.c index 2fadf51..7da8993 100644 --- a/stream/upb_decoder.c +++ b/stream/upb_decoder.c @@ -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; } diff --git a/stream/upb_decoder.h b/stream/upb_decoder.h index 0684ea2..1c62753 100644 --- a/stream/upb_decoder.h +++ b/stream/upb_decoder.h @@ -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; }; |