components/nvs: fix formatting

This commit is contained in:
Ivan Grokhotkov 2016-09-22 21:05:47 +08:00
parent 076141aab9
commit e87d80d478
10 changed files with 89 additions and 102 deletions

View file

@ -263,12 +263,10 @@ static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, cons
if (length == nullptr) { if (length == nullptr) {
return ESP_ERR_NVS_INVALID_LENGTH; return ESP_ERR_NVS_INVALID_LENGTH;
} } else if (out_value == nullptr) {
else if (out_value == nullptr) {
*length = dataSize; *length = dataSize;
return ESP_OK; return ESP_OK;
} } else if (*length < dataSize) {
else if (*length < dataSize) {
*length = dataSize; *length = dataSize;
return ESP_ERR_NVS_INVALID_LENGTH; return ESP_ERR_NVS_INVALID_LENGTH;
} }

View file

@ -53,8 +53,7 @@ void HashList::insert(const Item& item, size_t index)
void HashList::erase(size_t index) void HashList::erase(size_t index)
{ {
for (auto it = std::begin(mBlockList); it != std::end(mBlockList);) for (auto it = std::begin(mBlockList); it != std::end(mBlockList);) {
{
bool haveEntries = false; bool haveEntries = false;
for (size_t i = 0; i < it->mCount; ++i) { for (size_t i = 0; i < it->mCount; ++i) {
if (it->mNodes[i].mIndex == index) { if (it->mNodes[i].mIndex == index) {
@ -70,8 +69,7 @@ void HashList::erase(size_t index)
++it; ++it;
mBlockList.erase(tmp); mBlockList.erase(tmp);
delete static_cast<HashListBlock*>(tmp); delete static_cast<HashListBlock*>(tmp);
} } else {
else {
++it; ++it;
} }
} }
@ -81,8 +79,7 @@ void HashList::erase(size_t index)
size_t HashList::find(size_t start, const Item& item) size_t HashList::find(size_t start, const Item& item)
{ {
const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff; const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff;
for (auto it = std::begin(mBlockList); it != std::end(mBlockList); ++it) for (auto it = std::begin(mBlockList); it != std::end(mBlockList); ++it) {
{
for (size_t index = 0; index < it->mCount; ++index) { for (size_t index = 0; index < it->mCount; ++index) {
HashListNode& e = it->mNodes[index]; HashListNode& e = it->mNodes[index];
if (e.mIndex >= start && if (e.mIndex >= start &&

View file

@ -47,8 +47,7 @@ protected:
uint32_t mHash : 24; uint32_t mHash : 24;
}; };
struct HashListBlock : public intrusive_list_node<HashList::HashListBlock> struct HashListBlock : public intrusive_list_node<HashList::HashListBlock> {
{
HashListBlock(); HashListBlock();
static const size_t BYTE_SIZE = 128; static const size_t BYTE_SIZE = 128;

View file

@ -59,11 +59,9 @@ esp_err_t Page::load(uint32_t sectorNumber)
break; break;
} }
} }
} } else if (header.mCrc32 != header.calculateCrc32()) {
else if (header.mCrc32 != header.calculateCrc32()) {
header.mState = PageState::CORRUPT; header.mState = PageState::CORRUPT;
} } else {
else {
mState = header.mState; mState = header.mState;
mSeqNumber = header.mSeqNumber; mSeqNumber = header.mSeqNumber;
} }
@ -208,6 +206,7 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c
return err; return err;
} }
} }
} }
return ESP_OK; return ESP_OK;
} }
@ -327,8 +326,7 @@ esp_err_t Page::eraseEntryAndSpan(size_t index)
return rc; return rc;
} }
} }
} } else {
else {
auto rc = alterEntryState(index, EntryState::ERASED); auto rc = alterEntryState(index, EntryState::ERASED);
if (rc != ESP_OK) { if (rc != ESP_OK) {
return rc; return rc;
@ -538,8 +536,7 @@ esp_err_t Page::mLoadEntryTable()
} }
} }
} }
} } else if (mState == PageState::FULL || mState == PageState::FREEING) {
else if (mState == PageState::FULL || mState == PageState::FREEING) {
// We have already filled mHashList for page in active state. // We have already filled mHashList for page in active state.
// Do the same for the case when page is in full or freeing state. // Do the same for the case when page is in full or freeing state.
Item item; Item item;
@ -675,8 +672,7 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
size_t cachedIndex = mHashList.find(start, Item(nsIndex, datatype, 0, key)); size_t cachedIndex = mHashList.find(start, Item(nsIndex, datatype, 0, key));
if (cachedIndex < ENTRY_COUNT) { if (cachedIndex < ENTRY_COUNT) {
start = cachedIndex; start = cachedIndex;
} } else {
else {
return ESP_ERR_NVS_NOT_FOUND; return ESP_ERR_NVS_NOT_FOUND;
} }
} }
@ -793,18 +789,15 @@ void Page::debugDump() const
EntryState state = mEntryTable.get(i); EntryState state = mEntryTable.get(i);
if (state == EntryState::EMPTY) { if (state == EntryState::EMPTY) {
printf("E\n"); printf("E\n");
} } else if (state == EntryState::ERASED) {
else if (state == EntryState::ERASED) {
printf("X\n"); printf("X\n");
} } else if (state == EntryState::WRITTEN) {
else if (state == EntryState::WRITTEN) {
Item item; Item item;
readEntry(i, item); readEntry(i, item);
if (skip == 0) { if (skip == 0) {
printf("W ns=%2u type=%2u span=%3u key=\"%s\"\n", item.nsIndex, static_cast<unsigned>(item.datatype), item.span, item.key); printf("W ns=%2u type=%2u span=%3u key=\"%s\"\n", item.nsIndex, static_cast<unsigned>(item.datatype), item.span, item.key);
skip = item.span - 1; skip = item.span - 1;
} } else {
else {
printf("D\n"); printf("D\n");
skip--; skip--;
} }

View file

@ -167,9 +167,11 @@ public:
protected: protected:
class Header { class Header
{
public: public:
Header() { Header()
{
std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX); std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX);
} }

View file

@ -47,8 +47,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount)
if (mPageList.empty()) { if (mPageList.empty()) {
mSeqNumber = 0; mSeqNumber = 0;
return activatePage(); return activatePage();
} } else {
else {
uint32_t lastSeqNo; uint32_t lastSeqNo;
assert(mPageList.back().getSeqNumber(lastSeqNo) == ESP_OK); assert(mPageList.back().getSeqNumber(lastSeqNo) == ESP_OK);
mSeqNumber = lastSeqNo + 1; mSeqNumber = lastSeqNo + 1;

View file

@ -103,8 +103,7 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
if (err != ESP_OK) { if (err != ESP_OK) {
return err; return err;
} }
} } else if (err != ESP_OK) {
else if (err != ESP_OK) {
return err; return err;
} }