mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
mtd: add fast path to mtd_write_page()
If we overwrite a whole sector, don't perform a read-modify-write cycle.
This commit is contained in:
parent
ebc869a83f
commit
44476137e3
@ -183,6 +183,12 @@ static size_t _write_sector(mtd_dev_t *mtd, const void *data, uint32_t sector,
|
||||
len = sector_size - offset;
|
||||
}
|
||||
|
||||
/* fast path: skip reading the sector if we overwrite it completely */
|
||||
if (offset == 0 && len == sector_size) {
|
||||
work = (void *)data;
|
||||
goto write;
|
||||
}
|
||||
|
||||
/* copy sector to RAM */
|
||||
res = mtd_read_page(mtd, work, sector_page, 0, sector_size);
|
||||
if (res < 0) {
|
||||
@ -198,6 +204,7 @@ static size_t _write_sector(mtd_dev_t *mtd, const void *data, uint32_t sector,
|
||||
/* modify sector in RAM */
|
||||
memcpy(work + offset, data, len);
|
||||
|
||||
write:
|
||||
/* write back modified sector copy */
|
||||
res = mtd_write_page_raw(mtd, work, sector_page, 0, sector_size);
|
||||
if (res < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user