Skip to content

Commit b3a503a

Browse files
committed
Optimised _dirty flag.
_dirty set only if the value being written is different from the existing value in the cache.
1 parent 87c59b1 commit b3a503a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libraries/EEPROM/EEPROM.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ void EEPROMClass::write(int address, uint8_t value) {
8686
if(!_data)
8787
return;
8888

89-
_data[address] = value;
90-
_dirty = true;
89+
// Optimise _dirty. Only flagged if data written is different.
90+
uint8_t* pData = &_data[address];
91+
if (*pData != value)
92+
{
93+
*pData = value;
94+
_dirty = true;
95+
}
9196
}
9297

9398
bool EEPROMClass::commit() {

0 commit comments

Comments
 (0)