diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-11-23 16:19:22 -0800 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-11-23 16:19:22 -0800 |
commit | b5f5ee867e6c91b77490dc8894236f17a47bde00 (patch) | |
tree | bb11d1e7881d27dfbcb8cef895be53812c57132e /benchmarks/parsetostruct.upb.c | |
parent | 99ae0ed39723b9c8f97fbdde070681e2a8b7a20e (diff) |
Refinement of upb_bytesrc interface.
Added a upb_byteregion that tracks a region of
the input buffer; decoders use this instead of
using a upb_bytesrc directly. upb_byteregion
is also used as the way of passing a string to
a upb_handlers callback. This symmetry makes
decoders compose better; if you want to take
a parsed string and decode it as something else,
you can take the string directly from the callback
and feed it as input to another parser.
A commented-out version of a pinning interface
is present; I decline to actually implement it
(and accept its extra complexity) until/unless
it is clear that it is actually a win. But it
is included as a proof-of-concept, to show that
it fits well with the existing interface.
Diffstat (limited to 'benchmarks/parsetostruct.upb.c')
-rw-r--r-- | benchmarks/parsetostruct.upb.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/benchmarks/parsetostruct.upb.c b/benchmarks/parsetostruct.upb.c index 5e7aa35..4eeafbb 100644 --- a/benchmarks/parsetostruct.upb.c +++ b/benchmarks/parsetostruct.upb.c @@ -8,6 +8,7 @@ #include "upb/pb/glue.h" static const upb_msgdef *def; +char *str; static size_t len; static void *msg[NUM_MESSAGES]; static upb_stringsrc strsrc; @@ -33,7 +34,7 @@ static bool initialize() upb_symtab_unref(s); // Read the message data itself. - char *str = upb_readfile(MESSAGE_FILE, &len); + str = upb_readfile(MESSAGE_FILE, &len); if(str == NULL) { fprintf(stderr, "Error reading " MESSAGE_FILE "\n"); return false; @@ -43,7 +44,6 @@ static bool initialize() msg[i] = upb_stdmsg_new(def); upb_stringsrc_init(&strsrc); - upb_stringsrc_reset(&strsrc, str, len); upb_handlers *h = upb_handlers_new(); upb_accessors_reghandlers(h, def); if (!JIT) h->should_jit = false; @@ -70,8 +70,8 @@ static size_t run(int i) upb_status status = UPB_STATUS_INIT; i %= NUM_MESSAGES; upb_msg_clear(msg[i], def); - upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), - 0, UPB_NONDELIMITED, msg[i]); + upb_stringsrc_reset(&strsrc, str, len); + upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), msg[i]); upb_decoder_decode(&d, &status); if(!upb_ok(&status)) goto err; return len; |