Merge pull request #632 from robekras/patch-1
Fix lfs_file_rawseek performance issue
This commit is contained in:
@@ -3100,6 +3100,27 @@ static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file,
|
|||||||
return npos;
|
return npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we're only reading and our new offset is still in the file's cache
|
||||||
|
// we can avoid flushing and needing to reread the data
|
||||||
|
if (
|
||||||
|
#ifndef LFS_READONLY
|
||||||
|
!(file->flags & LFS_F_WRITING)
|
||||||
|
#else
|
||||||
|
true
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
int oindex = lfs_ctz_index(lfs, &(lfs_off_t){file->pos});
|
||||||
|
lfs_off_t noff = npos;
|
||||||
|
int nindex = lfs_ctz_index(lfs, &noff);
|
||||||
|
if (oindex == nindex
|
||||||
|
&& noff >= file->cache.off
|
||||||
|
&& noff < file->cache.off + file->cache.size) {
|
||||||
|
file->pos = npos;
|
||||||
|
file->off = noff;
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write out everything beforehand, may be noop if rdonly
|
// write out everything beforehand, may be noop if rdonly
|
||||||
int err = lfs_file_flush(lfs, file);
|
int err = lfs_file_flush(lfs, file);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user