summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-08-27 11:10:13 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-08-27 11:10:13 -0700
commitf17ed90f7704d77e3eb59a6f6b693ab4c598936a (patch)
tree48c0b69db3984577d77219eb861783b6bed16d24 /benchmarks
parentb276aa78b6d04a35420ce699ae51771550b97d11 (diff)
Some cleanup and reformatting, fixed the benchmarks.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/parsetostruct.upb_table.c51
1 files changed, 26 insertions, 25 deletions
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;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback