summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2010-07-11 16:58:44 -0700
committerJoshua Haberman <joshua@reverberate.org>2010-07-11 16:58:44 -0700
commitfcfc37e7d41f87bc9ff5ecfb64e0aebb3457c633 (patch)
tree0f18f8158ad6c1048a79f62d60719891898411da
parentc7a95061a7c02ffeebd71eeb56bf19fc1c1797dd (diff)
Reduce decoder memory usage.
The "field" entry was only being used to determine whether we were inside a group, but the "end_offset" member contains enough information to tell us that.
-rw-r--r--Makefile2
-rw-r--r--stream/upb_decoder.c12
2 files changed, 6 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 2b2a269..c37df72 100644
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ OTHERSRC=src/upb_encoder.c src/upb_text.c
# Override the optimization level for upb_def.o, because it is not in the
# critical path but gets very large when -O3 is used.
core/upb_def.o: core/upb_def.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -O0 -c -o $@ $<
+ $(CC) $(CFLAGS) $(CPPFLAGS) -Os -c -o $@ $<
core/upb_def.lo: core/upb_def.c
$(CC) $(CFLAGS) $(CPPFLAGS) -Os -c -o $@ $< -fPIC
diff --git a/stream/upb_decoder.c b/stream/upb_decoder.c
index 52fc72b..c06660f 100644
--- a/stream/upb_decoder.c
+++ b/stream/upb_decoder.c
@@ -29,8 +29,7 @@ static int64_t upb_zzdec_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); }
// upb_decoder_frame is one frame of that stack.
typedef struct {
upb_msgdef *msgdef;
- upb_fielddef *field;
- upb_strlen_t end_offset; // For groups, -1.
+ upb_strlen_t end_offset; // For groups, UPB_GROUP_END_OFFSET.
} upb_decoder_frame;
struct upb_decoder {
@@ -57,9 +56,6 @@ struct upb_decoder {
// The overall stream offset of the beginning of "buf".
uint32_t buf_stream_offset;
- // Fielddef for the key we just read.
- upb_fielddef *field;
-
// Wire type of the key we just read.
upb_wire_type_t wire_type;
@@ -68,6 +64,9 @@ struct upb_decoder {
upb_strlen_t packed_end_offset;
+ // Fielddef for the key we just read.
+ upb_fielddef *field;
+
// We keep a stack of messages we have recursed into.
upb_decoder_frame *top, *limit, stack[UPB_MAX_NESTING];
};
@@ -455,7 +454,6 @@ bool upb_decoder_getstr(upb_decoder *d, upb_string *str) {
static bool upb_decoder_skipgroup(upb_decoder *d);
bool upb_decoder_startmsg(upb_decoder *d) {
- d->top->field = d->field;
if(++d->top >= d->limit) {
upb_seterr(&d->src.status, UPB_ERROR_MAX_NESTING_EXCEEDED,
"Nesting exceeded maximum (%d levels)\n",
@@ -476,7 +474,7 @@ bool upb_decoder_endmsg(upb_decoder *d) {
if(d->top > d->stack) {
--d->top;
if(!d->src.eof) {
- if(d->top->field->type == UPB_TYPE(GROUP))
+ if(d->top->end_offset == UPB_GROUP_END_OFFSET)
upb_decoder_skipgroup(d);
else
upb_decoder_skipbytes(d, d->top->end_offset - upb_decoder_offset(d));
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback