summaryrefslogtreecommitdiff
path: root/benchmarks/parsetoproto2.upb.cc
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/parsetoproto2.upb.cc')
-rw-r--r--benchmarks/parsetoproto2.upb.cc24
1 files changed, 8 insertions, 16 deletions
diff --git a/benchmarks/parsetoproto2.upb.cc b/benchmarks/parsetoproto2.upb.cc
index 03a1039..75cd10c 100644
--- a/benchmarks/parsetoproto2.upb.cc
+++ b/benchmarks/parsetoproto2.upb.cc
@@ -24,7 +24,6 @@
#include <google/protobuf/descriptor.h>
#undef private
-char *str;
static size_t len;
MESSAGE_CIDENT msg[NUM_MESSAGES];
MESSAGE_CIDENT msg2;
@@ -54,13 +53,9 @@ 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_byteregion *ref = upb_value_getbyteregion(val);
- uint32_t len;
- (*str)->assign(
- upb_byteregion_getptr(ref, upb_byteregion_startofs(ref), &len),
- upb_byteregion_len(ref));
- assert(len == upb_byteregion_len(ref));
+ const upb_strref *ref = upb_value_getstrref(val);
// XXX: only supports contiguous strings atm.
+ (*str)->assign(ref->ptr, ref->len);
return UPB_CONTINUE;
}
@@ -69,13 +64,9 @@ upb_flow_t proto2_append_str(void *_r, upb_value fval, upb_value val) {
typedef google::protobuf::RepeatedPtrField<std::string> R;
(void)fval;
R *r = (R*)_r;
- const upb_byteregion *ref = upb_value_getbyteregion(val);
+ const upb_strref *ref = upb_value_getstrref(val);
// XXX: only supports contiguous strings atm.
- uint32_t len;
- r->Add()->assign(
- upb_byteregion_getptr(ref, upb_byteregion_startofs(ref), &len),
- upb_byteregion_len(ref));
- assert(len == upb_byteregion_len(ref));
+ r->Add()->assign(ref->ptr, ref->len);
return UPB_CONTINUE;
}
@@ -274,7 +265,7 @@ static bool initialize()
upb_symtab_unref(s);
// Read the message data itself.
- str = upb_readfile(MESSAGE_FILE, &len);
+ char *str = upb_readfile(MESSAGE_FILE, &len);
if(str == NULL) {
fprintf(stderr, "Error reading " MESSAGE_FILE "\n");
return false;
@@ -284,6 +275,7 @@ 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;
@@ -304,8 +296,8 @@ static size_t run(int i)
(void)i;
upb_status status = UPB_STATUS_INIT;
msg[i % NUM_MESSAGES].Clear();
- upb_stringsrc_reset(&strsrc, str, len);
- upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), &msg[i % NUM_MESSAGES]);
+ 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;
return len;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback