From f17ed90f7704d77e3eb59a6f6b693ab4c598936a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 27 Aug 2009 11:10:13 -0700 Subject: Some cleanup and reformatting, fixed the benchmarks. --- benchmarks/parsetostruct.upb_table.c | 51 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb_table.c index 751c982..9daa8e0 100644 --- a/benchmarks/parsetostruct.upb_table.c +++ b/benchmarks/parsetostruct.upb_table.c @@ -3,45 +3,47 @@ #include "upb_context.h" #include "upb_msg.h" +#include "upb_mm.h" -static struct upb_context c; -static struct upb_string str; -static struct upb_msg_parse_state s; -static struct upb_msg *m; -static void *data[NUM_MESSAGES]; +static struct upb_context *c; +static struct upb_string *str; +static struct upb_msgdef *def; +static struct upb_msg *msgs[NUM_MESSAGES]; static bool initialize() { /* Initialize upb state, parse descriptor. */ - upb_context_init(&c); - struct upb_string fds; - if(!upb_strreadfile(MESSAGE_DESCRIPTOR_FILE, &fds)) { + c = upb_context_new(); + struct upb_string *fds = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE); + if(!fds) { fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ".\n"); return false; } - if(!upb_context_parsefds(&c, &fds)) { + if(!upb_context_parsefds(c, fds)) { fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ".\n"); return false; } - upb_strfree(fds); + upb_string_unref(fds); char class_name[] = MESSAGE_NAME; struct upb_string proto_name; proto_name.ptr = class_name; proto_name.byte_len = sizeof(class_name)-1; - struct upb_symtab_entry *e = upb_context_lookup(&c, &proto_name); - if(!e || e->type != UPB_SYM_MESSAGE) { + struct upb_symtab_entry e; + upb_status_t success = upb_context_lookup(c, &proto_name, &e); + if(!success || e.type != UPB_SYM_MESSAGE) { fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n", - UPB_STRARG(proto_name)); + UPB_STRARG(&proto_name)); return false; } - m = e->ref.msg; + def = e.ref.msg; for(int i = 0; i < 32; i++) - data[i] = upb_msgdata_new(m); + msgs[i] = upb_msg_new(def); /* Read the message data itself. */ - if(!upb_strreadfile(MESSAGE_FILE, &str)) { + str = upb_strreadfile(MESSAGE_FILE); + if(!str) { fprintf(stderr, "Error reading " MESSAGE_FILE "\n"); return false; } @@ -51,19 +53,18 @@ static bool initialize() static void cleanup() { for(int i = 0; i < 32; i++) - upb_msgdata_free(data[i], m, true); - upb_strfree(str); - upb_context_free(&c); + upb_msg_unref(msgs[i]); + upb_string_unref(str); + upb_context_unref(c); } static size_t run(int i) { - size_t read; - upb_msg_parse_reset(&s, data[i%NUM_MESSAGES], m, false, BYREF); - upb_status_t status = upb_msg_parse(&s, str.ptr, str.byte_len, &read); - if(status != UPB_STATUS_OK && read != str.byte_len) { - fprintf(stderr, "Error. :( error=%d, read=%zu\n", status, read); + upb_status_t status; + status = upb_msg_parsestr(msgs[i%NUM_MESSAGES], str->ptr, str->byte_len); + if(status != UPB_STATUS_OK) { + fprintf(stderr, "Error. :( error=%d\n", status); return 0; } - return read; + return str->byte_len; } -- cgit v1.2.3