diff options
author | Fredrik Meringdal <fredrikmeringdal@Fredriks-MacBook-Pro.local> | 2021-02-04 10:30:52 +0100 |
---|---|---|
committer | Fredrik Meringdal <fredrikmeringdal@Fredriks-MacBook-Pro.local> | 2021-02-04 10:30:52 +0100 |
commit | 002d83f26f11e45e25258b2843746cf1737be6ab (patch) | |
tree | 0d8f31f18809138ed661defefddb37b31e5997d7 | |
parent | 9b4c2c60debfd8ed81801425fd2a230c67bbd147 (diff) | |
download | rust_rrule-002d83f26f11e45e25258b2843746cf1737be6ab.zip |
using vecdeque instead of veq for buffering
-rw-r--r-- | src/rrule_iter.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/rrule_iter.rs b/src/rrule_iter.rs index 7cb0f80..421e8ab 100644 --- a/src/rrule_iter.rs +++ b/src/rrule_iter.rs @@ -5,6 +5,7 @@ use crate::{datetime::from_ordinal, RRule}; use crate::{datetime::Time, Frequenzy}; use chrono::prelude::*; use chrono_tz::Tz; +use std::collections::VecDeque; const MAX_YEAR: i32 = 9999; @@ -12,7 +13,7 @@ pub struct RRuleIter { pub counter_date: DateTime<Tz>, pub ii: IterInfo, pub timeset: Vec<Time>, - pub remain: Vec<DateTime<Tz>>, + pub remain: VecDeque<DateTime<Tz>>, pub finished: bool, } @@ -25,17 +26,15 @@ impl Iterator for RRuleIter { } if !self.remain.is_empty() { - return Some(self.remain.remove(0)); + return self.remain.pop_front(); } generate(self); if self.remain.is_empty() { self.finished = true; - None - } else { - Some(self.remain.remove(0)) } + self.remain.pop_front() } } @@ -85,7 +84,7 @@ pub fn generate(iter: &mut RRuleIter) { } if res >= options.dtstart { - iter.remain.push(res); + iter.remain.push_back(res); if let Some(count) = iter.ii.options.count { if count > 0 { @@ -121,7 +120,7 @@ pub fn generate(iter: &mut RRuleIter) { return; } if res >= options.dtstart { - iter.remain.push(res); + iter.remain.push_back(res); if let Some(count) = iter.ii.options.count { if count > 0 { @@ -184,7 +183,7 @@ impl IntoIterator for RRule { counter_date, ii, timeset, - remain: vec![], + remain: VecDeque::new(), finished: false, } } |