mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-26 06:03:18 -05:00
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:
parent
d7a94956eb
commit
8dc5d64333
5
db/db.rs
5
db/db.rs
@ -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())
|
||||
|
@ -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
|
||||
|
@ -382,8 +382,8 @@ impl Segment {
|
||||
self.index_once.call_once(|| {
|
||||
let index = unsafe { &mut *self.index.get() };
|
||||
*index = db.lock()
|
||||
.with_recording_playback(self.s.id, |playback| self.build_index(playback))
|
||||
.map_err(|e| { error!("Unable to build index for segment: {:?}", e); });
|
||||
.with_recording_playback(self.s.id, &mut |playback| self.build_index(playback))
|
||||
.map_err(|e| { error!("Unable to build index for segment: {:?}", e); });
|
||||
});
|
||||
let index: &'a _ = unsafe { &*self.index.get() };
|
||||
match *index {
|
||||
@ -627,7 +627,7 @@ impl Slice {
|
||||
}
|
||||
let truns =
|
||||
mp4.0.db.lock()
|
||||
.with_recording_playback(s.s.id, |playback| s.truns(playback, pos, len))?;
|
||||
.with_recording_playback(s.s.id, &mut |playback| s.truns(playback, pos, len))?;
|
||||
let truns = ARefs::new(truns);
|
||||
Ok(truns.map(|t| &t[r.start as usize .. r.end as usize]))
|
||||
}
|
||||
@ -2275,7 +2275,7 @@ mod bench {
|
||||
let rel_range_90k = 0 .. row.duration_90k;
|
||||
super::Segment::new(&db, &row, rel_range_90k, 1).unwrap()
|
||||
};
|
||||
db.with_recording_playback(segment.s.id, |playback| {
|
||||
db.with_recording_playback(segment.s.id, &mut |playback| {
|
||||
let v = segment.build_index(playback).unwrap(); // warm.
|
||||
b.bytes = v.len() as u64; // define the benchmark performance in terms of output bytes.
|
||||
b.iter(|| segment.build_index(playback).unwrap());
|
||||
|
@ -302,7 +302,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn get_frames(db: &db::LockedDatabase, id: CompositeId) -> Vec<Frame> {
|
||||
db.with_recording_playback(id, |rec| {
|
||||
db.with_recording_playback(id, &mut |rec| {
|
||||
let mut it = recording::SampleIndexIterator::new();
|
||||
let mut frames = Vec::new();
|
||||
while it.next(&rec.video_index).unwrap() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user