From 0941664215ed7fa4a8d53b6387d50c56df6757d0 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 20 May 2011 11:26:27 -0700 Subject: Add startseq/endseq handlers. Startseq/endseq handlers are called at the beginning and end of a sequence of repeated values. Protobuf does not really have direct support for this (repeated primitive fields do not delimit "begin" and "end" of the sequence) but we can infer them from the bytestream. The benefit of supporting them explicitly is that they get their own stack frame and closure, so we can avoid having to find the array's address over and over and deciding if we need to initialize it. This will also pave the way for better support of JSON, which does have explicit "startseq/endseq" markers: []. --- src/upb_msg.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/upb_msg.h') diff --git a/src/upb_msg.h b/src/upb_msg.h index a0b2ad2..ac113a8 100644 --- a/src/upb_msg.h +++ b/src/upb_msg.h @@ -144,14 +144,15 @@ typedef uint32_t upb_arraylen_t; struct _upb_array { upb_atomic_refcount_t refcount; // "len" and "size" are measured in elements, not bytes. - upb_arraylen_t len; - upb_arraylen_t size; + int32_t len; + int32_t size; char *ptr; }; void _upb_array_free(upb_array *a, upb_fielddef *f); INLINE upb_valueptr _upb_array_getptrforsize(upb_array *a, size_t type_size, - uint32_t elem) { + int32_t elem) { + assert(elem >= 0); upb_valueptr p; p._void = &a->ptr[elem * type_size]; return p; -- cgit v1.2.3