aboutsummaryrefslogtreecommitdiff
path: root/extmod/modujson.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-28 23:43:01 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-28 23:43:01 +0000
commit0d3cb6726ddc1bab9fdd11a0aaa259fb436da4b2 (patch)
tree7285c3f452efdfce8c0ecb302bbd0e2efcca0c15 /extmod/modujson.c
parent57aebe171459fd599f8d430c1ea1660ed307360c (diff)
py: Change vstr so that it doesn't null terminate buffer by default.
This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
Diffstat (limited to 'extmod/modujson.c')
-rw-r--r--extmod/modujson.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/extmod/modujson.c b/extmod/modujson.c
index 5023d8151..a7b889676 100644
--- a/extmod/modujson.c
+++ b/extmod/modujson.c
@@ -39,9 +39,7 @@ STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) {
vstr_t vstr;
vstr_init(&vstr, 8);
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, &vstr, obj, PRINT_JSON);
- mp_obj_t ret = mp_obj_new_str(vstr.buf, vstr.len, false);
- vstr_clear(&vstr);
- return ret;
+ return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);