nvs: remove search cache at page level

Since read cache was introduced at page level, search cache became
useless in terms of reducing the number of flash read operations.
In addition to that, search cache used an assumption that if pointers to
keys are identical, the keys are also identical, which was proven wrong
by applications which generate key names dynamically.

This change removes CachedFindInfo, and all its uses. This is done at
expense of a small extra number of CPU operations (looking up a value in
the read cache is slightly more expensive) but no extra flash read
operations.

Ref TW12505
Ref https://github.com/espressif/arduino-esp32/issues/365
This commit is contained in:
Ivan Grokhotkov
2017-05-12 12:18:08 +08:00
parent 15a6145961
commit bf01525fc1
3 changed files with 21 additions and 59 deletions
-21
View File
@@ -296,9 +296,6 @@ esp_err_t Page::eraseItem(uint8_t nsIndex, ItemType datatype, const char* key)
if (rc != ESP_OK) {
return rc;
}
if (CachedFindInfo(nsIndex, datatype, key) == mFindInfo) {
invalidateCache();
}
return eraseEntryAndSpan(index);
}
@@ -386,10 +383,6 @@ esp_err_t Page::moveItem(Page& other)
return ESP_ERR_NVS_NOT_FOUND;
}
if (mFindInfo.itemIndex() == mFirstUsedEntry) {
invalidateCache();
}
if (other.mState == PageState::UNINITIALIZED) {
auto err = other.initialize();
if (err != ESP_OK) {
@@ -608,7 +601,6 @@ esp_err_t Page::initialize()
mNextFreeEntry = 0;
std::fill_n(mEntryTable.data(), mEntryTable.byteSize() / sizeof(uint32_t), 0xffffffff);
invalidateCache();
return ESP_OK;
}
@@ -685,11 +677,6 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
return ESP_ERR_NVS_NOT_FOUND;
}
CachedFindInfo findInfo(nsIndex, datatype, key);
if (mFindInfo == findInfo) {
findBeginIndex = mFindInfo.itemIndex();
}
size_t start = mFirstUsedEntry;
if (findBeginIndex > mFirstUsedEntry && findBeginIndex < ENTRY_COUNT) {
start = findBeginIndex;
@@ -745,8 +732,6 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
}
itemIndex = i;
findInfo.setItemIndex(static_cast<uint32_t>(itemIndex));
mFindInfo = findInfo;
return ESP_OK;
}
@@ -805,12 +790,6 @@ esp_err_t Page::markFull()
}
return alterPageState(PageState::FULL);
}
void Page::invalidateCache()
{
mFindInfo = CachedFindInfo();
}
const char* Page::pageStateToName(PageState ps)
{