Commit fa2f1f72 authored by Damien George's avatar Damien George
Browse files

extmod, ujson: Slight reduction in code size.

parent 89e4657c
...@@ -55,9 +55,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { ...@@ -55,9 +55,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
const char *top = s + len; const char *top = s + len;
vstr_t vstr; vstr_t vstr;
vstr_init(&vstr, 8); vstr_init(&vstr, 8);
mp_obj_list_t *stack = NULL; mp_obj_list_t stack;
stack.len = 0;
stack.items = NULL;
mp_obj_t stack_top = MP_OBJ_NULL; mp_obj_t stack_top = MP_OBJ_NULL;
mp_obj_type_t *stack_top_type= NULL; mp_obj_type_t *stack_top_type = NULL;
mp_obj_t stack_key = MP_OBJ_NULL; mp_obj_t stack_key = MP_OBJ_NULL;
for (;;) { for (;;) {
cont: cont:
...@@ -104,11 +106,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { ...@@ -104,11 +106,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
s++; s++;
c = *s; c = *s;
switch (c) { switch (c) {
case 'b': c = '\b'; break; case 'b': c = 0x08; break;
case 'f': c = '\f'; break; case 'f': c = 0x0c; break;
case 'n': c = '\n'; break; case 'n': c = 0x0a; break;
case 'r': c = '\r'; break; case 'r': c = 0x0d; break;
case 't': c = '\t'; break; case 't': c = 0x09; break;
case 'u': if (s + 4 >= top) { goto fail; } else { assert(0); } //vstr_add_char(&vstr, s[0] case 'u': if (s + 4 >= top) { goto fail; } else { assert(0); } //vstr_add_char(&vstr, s[0]
} }
} }
...@@ -158,12 +160,12 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { ...@@ -158,12 +160,12 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
// no object at all // no object at all
goto fail; goto fail;
} }
if (stack == NULL || stack->len == 0) { if (stack.len == 0) {
// finished; compound object // finished; compound object
goto success; goto success;
} }
stack->len -= 1; stack.len -= 1;
stack_top = stack->items[stack->len]; stack_top = stack.items[stack.len];
stack_top_type = mp_obj_get_type(stack_top); stack_top_type = mp_obj_get_type(stack_top);
goto cont; goto cont;
} }
...@@ -193,10 +195,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { ...@@ -193,10 +195,11 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
} }
} }
if (enter) { if (enter) {
if (stack == NULL) { if (stack.items == NULL) {
stack = mp_obj_new_list(1, &stack_top); mp_obj_list_init(&stack, 1);
stack.items[0] = stack_top;
} else { } else {
mp_obj_list_append(stack, stack_top); mp_obj_list_append(&stack, stack_top);
} }
stack_top = next; stack_top = next;
stack_top_type = mp_obj_get_type(stack_top); stack_top_type = mp_obj_get_type(stack_top);
...@@ -212,7 +215,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) { ...@@ -212,7 +215,7 @@ STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
// unexpected chars // unexpected chars
goto fail; goto fail;
} }
if (stack != NULL && stack->len != 0) { if (stack.len != 0) {
goto fail; goto fail;
} }
vstr_clear(&vstr); vstr_clear(&vstr);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment