Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,22 @@ static int lfs_bd_cmp(lfs_t *lfs,
lfs_block_t block, lfs_off_t off,
const void *buffer, lfs_size_t size) {
const uint8_t *data = buffer;
lfs_size_t diff = 0;

for (lfs_off_t i = 0; i < size; i++) {
uint8_t dat;
int err = lfs_bd_read(lfs,
for (lfs_off_t i = 0; i < size; i += diff) {
uint8_t dat[8];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was 8 chosen.
Remember that this is being stored on the stack.
Any thoughts on making this configurable or reasons why it shouldn't be configurable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many configurations can be confusing.
I think 8 bytes is the best balance between performance and used space.


diff = lfs_min(size-i, sizeof(dat));
int res = lfs_bd_read(lfs,
pcache, rcache, hint-i,
block, off+i, &dat, 1);
if (err) {
return err;
block, off+i, &dat, diff);
if (res) {
return res;
}

if (dat != data[i]) {
return (dat < data[i]) ? LFS_CMP_LT : LFS_CMP_GT;
res = memcmp(dat, data + i, diff);
if (res) {
return res < 0 ? LFS_CMP_LT : LFS_CMP_GT;
}
}

Expand Down