From 4318a6d755b8365e4dfd4842c994003176cf6b70 Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Mon, 25 Nov 2019 17:21:54 +0200 Subject: [PATCH] py/objstringio: Slightly optimize stringio_copy_on_write for code size. With the memcpy() call placed last it avoids the effects of registers clobbering. It's definitely effective in non-inlined functions, but even here it is still making a small difference. For example, on stm32, this saves an extra `ldr` instruction to load `o->vstr` after the memcpy() returns. --- py/objstringio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/objstringio.c b/py/objstringio.c index 8f1f76113..cca4a8129 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -70,9 +70,9 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { const void *buf = o->vstr->buf; o->vstr->buf = m_new(char, o->vstr->len); - memcpy(o->vstr->buf, buf, o->vstr->len); o->vstr->fixed_buf = false; o->ref_obj = MP_OBJ_NULL; + memcpy(o->vstr->buf, buf, o->vstr->len); } STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {