Skip to content

Commit f076a25

Browse files
committed
perf: add inline hints to into_inner and I/O methods
Add #[inline] attributes to: - into_inner() methods across decoders (WAV, Vorbis, Symphonia) - read() and seek() implementations for ReadSeekSource These simple pass-through methods are good candidates for inlining as they just forward calls to their inner types without additional logic.
1 parent 798658b commit f076a25

File tree

8 files changed

+19
-3
lines changed

8 files changed

+19
-3
lines changed

benches/shared.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,36 @@ pub struct TestSource<T> {
1414
impl<T> Iterator for TestSource<T> {
1515
type Item = T;
1616

17+
#[inline]
1718
fn next(&mut self) -> Option<Self::Item> {
1819
self.samples.next()
1920
}
2021
}
2122

2223
impl<T> ExactSizeIterator for TestSource<T> {
24+
#[inline]
2325
fn len(&self) -> usize {
2426
self.samples.len()
2527
}
2628
}
2729

2830
impl<T: Sample> Source for TestSource<T> {
31+
#[inline]
2932
fn current_span_len(&self) -> Option<usize> {
3033
None // forever
3134
}
3235

36+
#[inline]
3337
fn channels(&self) -> ChannelCount {
3438
self.channels
3539
}
3640

41+
#[inline]
3742
fn sample_rate(&self) -> SampleRate {
3843
self.sample_rate
3944
}
4045

46+
#[inline]
4147
fn total_duration(&self) -> Option<Duration> {
4248
Some(self.total_duration)
4349
}

src/conversions/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ pub use self::sample::Sample;
1111
pub use self::sample_rate::SampleRateConverter;
1212

1313
mod channels;
14-
// TODO: < shouldn't be public ; there's a bug in Rust 1.4 and below that makes This
15-
// `pub` mandatory
16-
pub mod sample;
14+
mod sample;
1715
mod sample_rate;

src/decoder/flac.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ where
6767
})
6868
}
6969

70+
#[inline]
7071
pub fn into_inner(self) -> R {
7172
self.reader.into_inner()
7273
}

src/decoder/mp3.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ where
4545
current_span_offset: 0,
4646
})
4747
}
48+
49+
#[inline]
4850
pub fn into_inner(self) -> R {
4951
self.decoder.into_inner()
5052
}

src/decoder/read_seek_source.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,33 @@ pub struct ReadSeekSource<T: Read + Seek + Send + Sync> {
99
impl<T: Read + Seek + Send + Sync> ReadSeekSource<T> {
1010
/// Instantiates a new `ReadSeekSource<T>` by taking ownership and wrapping the provided
1111
/// `Read + Seek`er.
12+
#[inline]
1213
pub fn new(inner: T) -> Self {
1314
ReadSeekSource { inner }
1415
}
1516
}
1617

1718
impl<T: Read + Seek + Send + Sync> MediaSource for ReadSeekSource<T> {
19+
#[inline]
1820
fn is_seekable(&self) -> bool {
1921
true
2022
}
2123

24+
#[inline]
2225
fn byte_len(&self) -> Option<u64> {
2326
None
2427
}
2528
}
2629

2730
impl<T: Read + Seek + Send + Sync> Read for ReadSeekSource<T> {
31+
#[inline]
2832
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
2933
self.inner.read(buf)
3034
}
3135
}
3236

3337
impl<T: Read + Seek + Send + Sync> Seek for ReadSeekSource<T> {
38+
#[inline]
3439
fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
3540
self.inner.seek(pos)
3641
}

src/decoder/symphonia.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl SymphoniaDecoder {
5353
}
5454
}
5555

56+
#[inline]
5657
pub(crate) fn into_inner(self) -> MediaSourceStream {
5758
self.format.into_inner()
5859
}

src/decoder/vorbis.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ where
5454
next: 0,
5555
}
5656
}
57+
58+
#[inline]
5759
pub fn into_inner(self) -> OggStreamReader<R> {
5860
self.stream_reader
5961
}

src/decoder/wav.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ where
5858
})
5959
}
6060

61+
#[inline]
6162
pub fn into_inner(self) -> R {
6263
self.reader.reader.into_inner()
6364
}

0 commit comments

Comments
 (0)