Skip to content

Commit

Permalink
Pass through stream_position in ProgreessBarIter
Browse files Browse the repository at this point in the history
This avoids sending a stream_position update and also preserves optimizations that the underlying object may have made for stream_position.

For example, when wrapping a `BufReader` object, adding this impl allows the use of `.stream_position()` in functions that take a generic `Seek` object without causing the performance drop associated with the default impl of `stream_position` calling `seek(SeekFrom::Current(0))` and throwing away the buffer each time.
  • Loading branch information
rlee287 authored and djc committed Sep 15, 2021
1 parent 27c8cc3 commit 380c042
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/iter.rs
Expand Up @@ -134,6 +134,11 @@ impl<S: io::Seek> io::Seek for ProgressBarIter<S> {
pos
})
}
// Pass this through to preserve optimizations that the inner I/O object may use here
// Also avoid sending a set_position update when the position hasn't changed
fn stream_position(&mut self) -> io::Result<u64> {
self.it.stream_position()
}
}

impl<W: io::Write> io::Write for ProgressBarIter<W> {
Expand Down

0 comments on commit 380c042

Please sign in to comment.