py/modio: io.BufferedWriter: Describe flushing policy.

This commit is contained in:
Paul Sokolovsky 2016-03-25 14:59:30 +02:00
parent 063e6e7d0a
commit 2c81b9be28
1 changed files with 6 additions and 0 deletions

View File

@ -69,6 +69,12 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si
return org_size;
}
// Buffer flushing policy here is to flush entire buffer all the time.
// This allows e.g. to have a block device as backing storage and write
// entire block to it. memcpy below is not ideal and could be optimized
// in some cases. But the way it is now it at least ensures that buffer
// is word-aligned, to guard against obscure cases when it matters, e.g.
// https://github.com/micropython/micropython/issues/1863
memcpy(self->buf + self->len, buf, rem);
buf = (byte*)buf + rem;
size -= rem;