Shrunk the arena state that needs to be synced.

pull/13171/head
Joshua Haberman 4 years ago
parent 85a43e5461
commit 7f67f68c1c
  1. 12
      upb/decode.c
  2. 11
      upb/upb.c

@ -141,7 +141,6 @@ static const int8_t delim_ops[37] = {
typedef struct {
const char *limit; /* End of delimited region or end of buffer. */
upb_arena arena;
upb_arena *orig_parent;
int depth;
uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
jmp_buf err;
@ -613,11 +612,9 @@ bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
state.limit = buf + size;
state.depth = 64;
state.end_group = 0;
state.orig_parent = arena->parent;
state.arena = *arena;
if (arena->parent == arena) {
state.arena.parent = &state.arena;
}
state.arena.head = arena->head;
state.arena.last_size = arena->last_size;
state.arena.parent = arena;
if (setjmp(state.err)) {
ok = false;
@ -626,8 +623,7 @@ bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
ok = state.end_group == 0;
}
*arena = state.arena;
arena->parent = state.orig_parent;
arena->head = state.arena.head;
return ok;
}

@ -98,9 +98,9 @@ static upb_arena *arena_findroot(upb_arena *a) {
return a;
}
static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size) {
static void upb_arena_addblock(upb_arena *a, upb_arena *root, void *ptr,
size_t size) {
mem_block *block = ptr;
upb_arena *root = arena_findroot(a);
/* The block is for arena |a|, but should appear in the freelist of |root|. */
block->next = root->freelist;
@ -118,11 +118,12 @@ static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size) {
}
static bool upb_arena_allocblock(upb_arena *a, size_t size) {
upb_arena *root = arena_findroot(a);
size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve;
mem_block *block = upb_malloc(a->block_alloc, block_size);
mem_block *block = upb_malloc(root->block_alloc, block_size);
if (!block) return false;
upb_arena_addblock(a, block, block_size);
upb_arena_addblock(a, root, block, block_size);
return true;
}
@ -165,7 +166,7 @@ upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) {
a->freelist = NULL;
a->freelist_tail = NULL;
upb_arena_addblock(a, mem, n);
upb_arena_addblock(a, a, mem, n);
return a;
}

Loading…
Cancel
Save