From b3a503a9ef11df415faf5dcfb454f7dd9d3f074e Mon Sep 17 00:00:00 2001 From: timw1971 Date: Fri, 15 Jan 2016 15:15:22 +0000 Subject: [PATCH] Optimised _dirty flag. _dirty set only if the value being written is different from the existing value in the cache. --- libraries/EEPROM/EEPROM.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/EEPROM/EEPROM.cpp b/libraries/EEPROM/EEPROM.cpp index 41c484306..29e9579ac 100644 --- a/libraries/EEPROM/EEPROM.cpp +++ b/libraries/EEPROM/EEPROM.cpp @@ -86,8 +86,13 @@ void EEPROMClass::write(int address, uint8_t value) { if(!_data) return; - _data[address] = value; - _dirty = true; + // Optimise _dirty. Only flagged if data written is different. + uint8_t* pData = &_data[address]; + if (*pData != value) + { + *pData = value; + _dirty = true; + } } bool EEPROMClass::commit() {