make with_recording_playback less monomorphized

This is a minor code size reduction - instead of being monomorphized
into four variants (according to "cargo llvm-lines"), it's now
monomorphized into two. The stripped release binary on macOS is about
8kB smaller (0.15%). Not a huge improvement but better than nothing.

Benchmarks seem unchanged (though they have a lot of variance).
This commit is contained in:
Scott Lamb
2018-08-23 22:34:40 -07:00
parent d7a94956eb
commit 8dc5d64333
4 changed files with 13 additions and 11 deletions

View File

@@ -1153,8 +1153,9 @@ impl LockedDatabase {
/// Calls `f` with a single `recording_playback` row.
/// Note the lock is held for the duration of `f`.
/// This uses a LRU cache to reduce the number of retrievals from the database.
pub fn with_recording_playback<F, R>(&self, id: CompositeId, f: F) -> Result<R, Error>
where F: FnOnce(&RecordingPlayback) -> Result<R, Error> {
pub fn with_recording_playback<R>(&self, id: CompositeId,
f: &mut FnMut(&RecordingPlayback) -> Result<R, Error>)
-> Result<R, Error> {
// Check for uncommitted path.
let s = self.streams_by_id
.get(&id.stream())

View File

@@ -394,7 +394,7 @@ impl Segment {
// Slow path. Need to iterate through the index.
trace!("recording::Segment::new slow path, desired_range_90k={:?}, recording={:#?}",
self_.desired_range_90k, recording);
db.with_recording_playback(self_.id, |playback| {
db.with_recording_playback(self_.id, &mut |playback| {
let mut begin = Box::new(SampleIndexIterator::new());
let data = &(&playback).video_index;
let mut it = SampleIndexIterator::new();
@@ -437,8 +437,9 @@ impl Segment {
self_.video_sample_entry_id_and_trailing_zero =
recording.video_sample_entry_id |
(((it.duration_90k == 0) as i32) << 31);
Ok(self_)
})
Ok(())
})?;
Ok(self_)
}
pub fn video_sample_entry_id(&self) -> i32 {
@@ -632,7 +633,7 @@ mod tests {
fn get_frames<F, T>(db: &db::Database, segment: &Segment, f: F) -> Vec<T>
where F: Fn(&SampleIndexIterator) -> T {
let mut v = Vec::new();
db.lock().with_recording_playback(segment.id, |playback| {
db.lock().with_recording_playback(segment.id, &mut |playback| {
segment.foreach(playback, |it| { v.push(f(it)); Ok(()) })
}).unwrap();
v