Skip to content

Commit

Permalink
[zephyr] Small settings load optimization (#18506)
Browse files Browse the repository at this point in the history
Zephyr settings API does not have a function for loading
a single key, so Matter uses an API for loading a subtree
of keys. This can be slightly optimized by exiting the
key lookup after finding an exact match.
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Feb 8, 2024
1 parent 138c1a0 commit 1251969
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/platform/Zephyr/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ int LoadEntryCallback(const char * name, size_t entrySize, settings_read_cb read
entry.result = bytesRead > 0 ? CHIP_NO_ERROR : CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

return 0;
// Return 1 to stop processing further keys
return 1;
}

int DeleteSubtreeCallback(const char * name, size_t /* entrySize */, settings_read_cb /* readCb */, void * /* cbArg */,
Expand Down
6 changes: 4 additions & 2 deletions src/platform/Zephyr/ZephyrConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ int ConfigValueCallback(const char * name, size_t configSize, settings_read_cb r
{
request.result = CHIP_ERROR_BUFFER_TOO_SMALL;
request.configSize = configSize;
return 0;
return 1;
}

// Found requested key
const ssize_t bytesRead = readCb(cbArg, request.destination, request.bufferSize);
request.result = bytesRead > 0 ? CHIP_NO_ERROR : CHIP_ERROR_PERSISTED_STORAGE_FAILED;
request.configSize = bytesRead > 0 ? bytesRead : 0;
return 0;

// Return 1 to stop processing further keys
return 1;
}

// Read configuration value of maximum size `bufferSize` and store the actual size in `configSize`.
Expand Down

0 comments on commit 1251969

Please sign in to comment.