diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-08-19 17:19:53 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-08-19 17:19:53 -0700 |
commit | 06b8181f975d66341fe8b96999c911a8ed24447c (patch) | |
tree | de95c722ffdc9e69dc5b54d5b3c034e40b538de4 /upb/pb/glue.c | |
parent | 40f271b8543abb6fadda19c350b61cd06f176648 (diff) |
Benchmark to parse into proto2 messages.
Diffstat (limited to 'upb/pb/glue.c')
-rw-r--r-- | upb/pb/glue.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/upb/pb/glue.c b/upb/pb/glue.c index 6b52435..e13db3e 100644 --- a/upb/pb/glue.c +++ b/upb/pb/glue.c @@ -53,8 +53,8 @@ void upb_msgtotext(upb_string *str, upb_msg *msg, upb_msgdef *md, #endif // TODO: read->load. -void upb_read_descriptor(upb_symtab *symtab, const char *str, size_t len, - upb_status *status) { +upb_def **upb_load_descriptor(const char *str, size_t len, int *n, + upb_status *status) { upb_stringsrc strsrc; upb_stringsrc_init(&strsrc); upb_stringsrc_reset(&strsrc, str, len); @@ -70,12 +70,17 @@ void upb_read_descriptor(upb_symtab *symtab, const char *str, size_t len, upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), 0, UINT64_MAX, &r); upb_decoder_decode(&d, status); - int n; - upb_def **defs = upb_descreader_getdefs(&r, &n); + upb_def **defs = upb_descreader_getdefs(&r, n); + upb_def **defscopy = malloc(sizeof(upb_def*) * (*n)); + memcpy(defscopy, defs, sizeof(upb_def*) * (*n)); + + upb_descreader_uninit(&r); + upb_stringsrc_uninit(&strsrc); + upb_decoder_uninit(&d); // Set default accessors and layouts on all messages. - for(int i = 0; i < n; i++) { - upb_def *def = defs[i]; + for(int i = 0; i < *n; i++) { + upb_def *def = defscopy[i]; upb_msgdef *md = upb_dyncast_msgdef(def); if (!md) continue; // For field in msgdef: @@ -87,13 +92,16 @@ void upb_read_descriptor(upb_symtab *symtab, const char *str, size_t len, upb_msgdef_layout(md); } - if (upb_ok(status)) upb_symtab_add(symtab, defs, n, status); + return defscopy; +} +void upb_read_descriptor(upb_symtab *s, const char *str, size_t len, + upb_status *status) { + int n; + upb_def **defs = upb_load_descriptor(str, len, &n, status); + if (upb_ok(status)) upb_symtab_add(s, defs, n, status); for(int i = 0; i < n; i++) upb_def_unref(defs[i]); - - upb_descreader_uninit(&r); - upb_stringsrc_uninit(&strsrc); - upb_decoder_uninit(&d); + free(defs); } char *upb_readfile(const char *filename, size_t *len) { |