From 90c4c73887f785577a20048cb44c2ac32d39e98b Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Wed, 11 Nov 2020 19:19:44 +1100 Subject: [PATCH] Used cached result of self.trajectory.get_num_atoms() rather than storing it in TrajectoryIterator --- src/iterator.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/iterator.rs b/src/iterator.rs index 71b3657..540a950 100644 --- a/src/iterator.rs +++ b/src/iterator.rs @@ -11,7 +11,6 @@ fn into_iter_inner(mut traj: T) -> TrajectoryIterator { trajectory: traj, item: Rc::new(frame), has_error: false, - num_atoms, } } @@ -42,14 +41,14 @@ pub struct TrajectoryIterator { trajectory: T, item: Rc, has_error: bool, - num_atoms: Result, } impl TrajectoryIterator { /// Inner function for `next()` to seperate error handling from iteration logic fn next_inner(&mut self) -> ::Item { // If we couldn't read the number of frames when we called into_iter, return that error now - let num_atoms = match &self.num_atoms { + // It's OK to do this every frame because the result is cached by Trajectory + let num_atoms = match &self.trajectory.get_num_atoms() { &Ok(n) => n, Err(e) => Err(Error::CheckNAtomsDuringIter(Box::new(e.clone())))?, };