summaryrefslogtreecommitdiff
path: root/py/objstringio.c
diff options
context:
space:
mode:
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>2019-11-25 17:21:54 +0200
committerDamien George <damien.p.george@gmail.com>2019-11-26 14:26:24 +1100
commit4318a6d755b8365e4dfd4842c994003176cf6b70 (patch)
treed0225233c69c328f9bce4b31d6bda9b119696244 /py/objstringio.c
parent1675b98e74e6af0bd5edaf236a275dcb7735069e (diff)
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.
Diffstat (limited to 'py/objstringio.c')
-rw-r--r--py/objstringio.c2
1 files changed, 1 insertions, 1 deletions
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) {