From 6a1f3a66939308668ab8dce0d195afec16e02af9 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 14 Jul 2011 23:15:00 -0700 Subject: Major refactoring: upb_string is gone in favor of upb_strref. --- benchmarks/parsetostruct.upb_table.c | 44 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'benchmarks/parsetostruct.upb_table.c') diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb_table.c index f0ddb99..76cbf21 100644 --- a/benchmarks/parsetostruct.upb_table.c +++ b/benchmarks/parsetostruct.upb_table.c @@ -7,8 +7,8 @@ #include "upb_glue.h" #include "upb_msg.h" -static upb_string *input_str; static upb_msgdef *def; +static size_t len; static void *msg; static upb_stringsrc strsrc; static upb_decoder d; @@ -18,33 +18,22 @@ static bool initialize() // Initialize upb state, decode descriptor. upb_status status = UPB_STATUS_INIT; upb_symtab *s = upb_symtab_new(); - - upb_string *fds_str = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE); - if(fds_str == NULL) { - fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ":"), - upb_printerr(&status); - return false; - } - upb_read_descriptor(s, fds_str, &status); - upb_string_unref(fds_str); - + upb_read_descriptorfile(s, MESSAGE_DESCRIPTOR_FILE, &status); if(!upb_ok(&status)) { - fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ":"); - upb_printerr(&status); + upb_status_print(&status, stderr); return false; } - def = upb_dyncast_msgdef(upb_symtab_lookup(s, UPB_STRLIT(MESSAGE_NAME))); + def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME)); if(!def) { - fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n", - UPB_STRARG(UPB_STRLIT(MESSAGE_NAME))); + fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME); return false; } upb_symtab_unref(s); // Read the message data itself. - input_str = upb_strreadfile(MESSAGE_FILE); - if(input_str == NULL) { + char *str = upb_readfile(MESSAGE_FILE, &len); + if(str == NULL) { fprintf(stderr, "Error reading " MESSAGE_FILE "\n"); return false; } @@ -52,25 +41,17 @@ static bool initialize() msg = upb_stdmsg_new(def); upb_stringsrc_init(&strsrc); + upb_stringsrc_reset(&strsrc, str, len); upb_decoder_initformsgdef(&d, def); if (!BYREF) { - // Pretend the input string is stack-allocated, which will force its data - // to be copied instead of referenced. There is no good reason to do this, - // except to benchmark against proto2 more fairly, which in its open-source - // release does not support referencing the input string. - input_str->refcount.v = _UPB_STRING_REFCOUNT_STACK; + // TODO: use byref/byval accessors. } return true; } static void cleanup() { - if (!BYREF) { - // Undo our fabrication from before. - input_str->refcount.v = 1; - } - upb_string_unref(input_str); upb_stdmsg_free(msg, def); upb_def_unref(UPB_UPCAST(def)); upb_stringsrc_uninit(&strsrc); @@ -82,14 +63,13 @@ static size_t run(int i) (void)i; upb_status status = UPB_STATUS_INIT; upb_msg_clear(msg, def); - upb_stringsrc_reset(&strsrc, input_str); - upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), msg); + upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), 0, UINT64_MAX, msg); upb_decoder_decode(&d, &status); if(!upb_ok(&status)) goto err; - return upb_string_len(input_str); + return len; err: fprintf(stderr, "Decode error: "); - upb_printerr(&status); + upb_status_print(&status, stderr); return 0; } -- cgit v1.2.3