From 1b9b6bd1ad2d862a7df86096e96991135f0fb92c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 22 Dec 2011 12:15:45 -0800 Subject: Fixed the open-source build. --- benchmarks/parsestream.upb.c | 13 +++++++------ benchmarks/parsetoproto2.upb.cc | 36 ++++++++++++++++++++++++------------ benchmarks/parsetostruct.upb.c | 19 +++++++++++-------- 3 files changed, 42 insertions(+), 26 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/parsestream.upb.c b/benchmarks/parsestream.upb.c index 4d13e9d..0316a86 100644 --- a/benchmarks/parsestream.upb.c +++ b/benchmarks/parsestream.upb.c @@ -12,6 +12,7 @@ static size_t input_len; static const upb_msgdef *def; static upb_decoder decoder; static upb_stringsrc stringsrc; +static upb_decoderplan *plan; static upb_sflow_t startsubmsg(void *_m, upb_value fval) { (void)_m; @@ -53,11 +54,12 @@ static bool initialize() } upb_handlers *handlers = upb_handlers_new(); - if (!JIT) handlers->should_jit = false; // Cause all messages to be read, but do nothing when they are. upb_handlerset hset = {NULL, NULL, value, startsubmsg, NULL, NULL, NULL}; upb_handlers_reghandlerset(handlers, def, &hset); - upb_decoder_init(&decoder, handlers); + upb_decoder_init(&decoder); + plan = upb_decoderplan_new(handlers, JIT); + upb_decoder_resetplan(&decoder, plan, 0); upb_handlers_unref(handlers); upb_stringsrc_init(&stringsrc); return true; @@ -68,6 +70,7 @@ static void cleanup() free(input_str); upb_def_unref(UPB_UPCAST(def)); upb_decoder_uninit(&decoder); + upb_decoderplan_unref(plan); upb_stringsrc_uninit(&stringsrc); } @@ -76,10 +79,8 @@ static size_t run(int i) (void)i; upb_status status = UPB_STATUS_INIT; upb_stringsrc_reset(&stringsrc, input_str, input_len); - upb_decoder_reset(&decoder, upb_stringsrc_bytesrc(&stringsrc), - 0, UPB_NONDELIMITED, NULL); - upb_decoder_decode(&decoder, &status); - if(!upb_ok(&status)) goto err; + upb_decoder_resetinput(&decoder, upb_stringsrc_allbytes(&stringsrc), NULL); + if (upb_decoder_decode(&decoder) != UPB_OK) goto err; return input_len; err: diff --git a/benchmarks/parsetoproto2.upb.cc b/benchmarks/parsetoproto2.upb.cc index 75cd10c..988faad 100644 --- a/benchmarks/parsetoproto2.upb.cc +++ b/benchmarks/parsetoproto2.upb.cc @@ -30,6 +30,8 @@ MESSAGE_CIDENT msg2; static upb_stringsrc strsrc; static upb_decoder d; static const upb_msgdef *def; +static upb_decoderplan *p; +char *str; #define PROTO2_APPEND(type, ctype) \ upb_flow_t proto2_append_ ## type(void *_r, upb_value fval, upb_value val) { \ @@ -53,9 +55,13 @@ upb_flow_t proto2_setstr(void *m, upb_value fval, upb_value val) { const upb_fielddef *f = upb_value_getfielddef(fval); std::string **str = (std::string**)UPB_INDEX(m, f->offset, 1); if (*str == f->default_ptr) *str = new std::string; - const upb_strref *ref = upb_value_getstrref(val); + const upb_byteregion *reg = upb_value_getbyteregion(val); + size_t len; + (*str)->assign( + upb_byteregion_getptr(reg, upb_byteregion_startofs(reg), &len), + upb_byteregion_len(reg)); // XXX: only supports contiguous strings atm. - (*str)->assign(ref->ptr, ref->len); + assert(len == upb_byteregion_len(reg)); return UPB_CONTINUE; } @@ -64,9 +70,13 @@ upb_flow_t proto2_append_str(void *_r, upb_value fval, upb_value val) { typedef google::protobuf::RepeatedPtrField R; (void)fval; R *r = (R*)_r; - const upb_strref *ref = upb_value_getstrref(val); + const upb_byteregion *reg = upb_value_getbyteregion(val); + size_t len; + r->Add()->assign( + upb_byteregion_getptr(reg, upb_byteregion_startofs(reg), &len), + upb_byteregion_len(reg)); // XXX: only supports contiguous strings atm. - r->Add()->assign(ref->ptr, ref->len); + assert(len == upb_byteregion_len(reg)); return UPB_CONTINUE; } @@ -265,7 +275,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; @@ -275,11 +285,11 @@ static bool initialize() msg2.ParseFromArray(str, len); 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; - upb_decoder_init(&d, h); + p = upb_decoderplan_new(h, JIT); + upb_decoder_init(&d); + upb_decoder_resetplan(&d, p, 0); upb_handlers_unref(h); return true; @@ -289,6 +299,8 @@ static void cleanup() { upb_stringsrc_uninit(&strsrc); upb_decoder_uninit(&d); upb_def_unref(UPB_UPCAST(def)); + upb_decoderplan_unref(p); + free(str); } static size_t run(int i) @@ -296,10 +308,10 @@ static size_t run(int i) (void)i; upb_status status = UPB_STATUS_INIT; msg[i % NUM_MESSAGES].Clear(); - upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), - 0, UPB_NONDELIMITED, &msg[i % NUM_MESSAGES]); - upb_decoder_decode(&d, &status); - if(!upb_ok(&status)) goto err; + upb_stringsrc_reset(&strsrc, str, len); + upb_decoder_resetinput( + &d, upb_stringsrc_allbytes(&strsrc), &msg[i % NUM_MESSAGES]); + if (upb_decoder_decode(&d) != UPB_OK) goto err; return len; err: diff --git a/benchmarks/parsetostruct.upb.c b/benchmarks/parsetostruct.upb.c index 5e7aa35..9487577 100644 --- a/benchmarks/parsetostruct.upb.c +++ b/benchmarks/parsetostruct.upb.c @@ -12,6 +12,8 @@ static size_t len; static void *msg[NUM_MESSAGES]; static upb_stringsrc strsrc; static upb_decoder d; +static upb_decoderplan *p; +char *str; static bool initialize() { @@ -33,7 +35,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,12 +45,12 @@ 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; - upb_decoder_init(&d, h); + p = upb_decoderplan_new(h, JIT); + upb_decoder_init(&d); upb_handlers_unref(h); + upb_decoder_resetplan(&d, p, 0); if (!BYREF) { // TODO: use byref/byval accessors. @@ -63,6 +65,8 @@ static void cleanup() upb_def_unref(UPB_UPCAST(def)); upb_stringsrc_uninit(&strsrc); upb_decoder_uninit(&d); + upb_decoderplan_unref(p); + free(str); } static size_t run(int i) @@ -70,10 +74,9 @@ 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_decoder_decode(&d, &status); - if(!upb_ok(&status)) goto err; + upb_stringsrc_reset(&strsrc, str, len); + upb_decoder_resetinput(&d, upb_stringsrc_allbytes(&strsrc), msg[i]); + if (upb_decoder_decode(&d) != UPB_OK) goto err; return len; err: -- cgit v1.2.3