Skip to content

Commit 53d7cc0

Browse files
ittaccoigrr
authored andcommitted
Optimize EEPROM::put (#2487)
* EEPROM Library: Improved put function, compare data and only in case are different set _dirty flag, copy the data * It will grant that the _dirty flag is reset only at EEPROM.commit() and no changes are lost
1 parent 9fce9c7 commit 53d7cc0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libraries/EEPROM/EEPROM.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ class EEPROMClass {
5252
const T &put(int address, const T &t) {
5353
if (address < 0 || address + sizeof(T) > _size)
5454
return t;
55+
if (memcmp(_data + address, (const uint8_t*)&t, sizeof(T)) != 0) {
56+
_dirty = true;
57+
memcpy(_data + address, (const uint8_t*)&t, sizeof(T));
58+
}
5559

56-
memcpy(_data + address, (const uint8_t*) &t, sizeof(T));
57-
_dirty = true;
5860
return t;
5961
}
6062

0 commit comments

Comments
 (0)