Optimize Chunks::seek when offset is in current chunk (#37659)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan
2025-09-06 04:22:55 +00:00
committed by GitHub
parent 23dc1f5ea4
commit 47a475681f
+11 -9
View File
@@ -639,18 +639,20 @@ impl<'a> Chunks<'a> {
pub fn seek(&mut self, mut offset: usize) {
offset = offset.clamp(self.range.start, self.range.end);
let bias = if self.reversed {
Bias::Left
if self.reversed {
if offset > self.chunks.end() {
self.chunks.seek_forward(&offset, Bias::Left);
} else if offset <= *self.chunks.start() {
self.chunks.seek(&offset, Bias::Left);
}
} else {
Bias::Right
if offset >= self.chunks.end() {
self.chunks.seek_forward(&offset, Bias::Right);
} else if offset < *self.chunks.start() {
self.chunks.seek(&offset, Bias::Right);
}
};
if offset >= self.chunks.end() {
self.chunks.seek_forward(&offset, bias);
} else {
self.chunks.seek(&offset, bias);
}
self.offset = offset;
}