Skip to content

Commit 53d9004

Browse files
GadgetoidMichaelBell
authored andcommitted
py/objarray: Avoid double zero init on sized bytearrays.
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/objarray.c: Guard the explicit zero init in bytearray_make_new against being run, initialising the RAM to zero a second time, if this flag is set. Note that MICROPY_GC_CONSERVATIVE_CLEAR is default enabled by MICROPY_ENABLE_GC, and no ports currently override this value. Co-authored-by: Mike Bell <mdb036@gmail.com> Signed-off-by: Phil Howard <github@gadgetoid.com>
1 parent b2073a0 commit 53d9004

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

py/objarray.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ static mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args,
191191
// 1 arg, an integer: construct a blank bytearray of that length
192192
mp_uint_t len = mp_obj_get_int(args[0]);
193193
mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, len);
194+
// If this config is set then the GC clears all memory, so we don't need to.
195+
#if !MICROPY_GC_CONSERVATIVE_CLEAR
194196
memset(o->items, 0, len);
197+
#endif
195198
return MP_OBJ_FROM_PTR(o);
196199
} else {
197200
// 1 arg: construct the bytearray from that

0 commit comments

Comments
 (0)