Factored upb_map_entry into a shared place.

pull/13171/head
Joshua Haberman 5 years ago
parent 4c1a97ae9c
commit e911aae5f6
  1. 14
      upb/decode.c
  2. 7
      upb/def.c
  3. 15
      upb/msg.h

@ -492,19 +492,7 @@ static bool upb_decode_mapfield(upb_decstate *d, upb_decframe *frame,
const upb_msglayout_field *field, int len) { const upb_msglayout_field *field, int len) {
upb_map *map = *(upb_map**)&frame->msg[field->offset]; upb_map *map = *(upb_map**)&frame->msg[field->offset];
const upb_msglayout *entry = frame->layout->submsgs[field->submsg_index]; const upb_msglayout *entry = frame->layout->submsgs[field->submsg_index];
upb_map_entry ent;
/* The compiler ensures that all map entry messages have this layout. */
struct map_entry {
upb_msg_internal internal;
union {
upb_strview str; /* For str/bytes. */
upb_value val; /* For all other types. */
} k;
union {
upb_strview str; /* For str/bytes. */
upb_value val; /* For all other types. */
} v;
} ent;
if (!map) { if (!map) {
/* Lazily create map. */ /* Lazily create map. */

@ -869,10 +869,9 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) { if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) {
/* Map entries aren't actually stored, they are only used during parsing. upb_map_entry ent;
* For parsing, it helps a lot if all map entry messages have the same UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v));
* layout. */ return sizeof(ent.k);
return sizeof(upb_strview);
} else if (upb_fielddef_isseq(f)) { } else if (upb_fielddef_isseq(f)) {
return sizeof(void*); return sizeof(void*);
} else { } else {

@ -200,6 +200,21 @@ typedef struct {
upb_strtable table; upb_strtable table;
} upb_map; } upb_map;
/* Map entries aren't actually stored, they are only used during parsing. For
* parsing, it helps a lot if all map entry messages have the same layout.
* The compiler and def.c must ensure that all map entries have this layout. */
typedef struct {
upb_msg_internal internal;
union {
upb_strview str; /* For str/bytes. */
upb_value val; /* For all other types. */
} k;
union {
upb_strview str; /* For str/bytes. */
upb_value val; /* For all other types. */
} v;
} upb_map_entry;
/* Creates a new map on the given arena with this key/value type. */ /* Creates a new map on the given arena with this key/value type. */
upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size); upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size);

Loading…
Cancel
Save