Skip to content

Commit 1095bbb

Browse files
Gadgetoiddpgeorge
authored andcommitted
py/objstr: Avoid double zero init on sized bytes.
As per the implementation of m_malloc0, if MICROPY_GC_CONSERVATIVE_CLEAR is set then all RAM is guaranteed to be zero-init by gc_alloc. py/objstr.c: Guard the explicit zero init in bytes_make_new against being run, initialising the RAM to zero a second time, if this flag is set. Signed-off-by: Phil Howard <github@gadgetoid.com>
1 parent 53d9004 commit 1095bbb

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

py/objstr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ static mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
282282
}
283283
vstr_t vstr;
284284
vstr_init_len(&vstr, len);
285+
// If this config is set then the GC clears all memory, so we don't need to.
286+
#if !MICROPY_GC_CONSERVATIVE_CLEAR
285287
memset(vstr.buf, 0, len);
288+
#endif
286289
return mp_obj_new_bytes_from_vstr(&vstr);
287290
}
288291

0 commit comments

Comments
 (0)