diff options
author | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-10-16 23:00:10 +0200 |
---|---|---|
committer | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-10-16 23:00:10 +0200 |
commit | 0d7e3c3a74c470ec34c4923277817c968c7ff19b (patch) | |
tree | 290588f3277fc6e9cc7eb955dd5b4018a2509eb4 /src | |
parent | 72c172c322e65b112bb6aa4419177ed70fcf4d6f (diff) | |
download | rust_rrule-0d7e3c3a74c470ec34c4923277817c968c7ff19b.zip |
got some serious performance improvement from once_cell!!!!
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/masks.rs | 5 | ||||
-rw-r--r-- | src/yearinfo.rs | 4 |
3 files changed, 8 insertions, 2 deletions
@@ -1,4 +1,5 @@ extern crate chrono; +extern crate once_cell; pub mod datetime; pub mod iter; diff --git a/src/masks.rs b/src/masks.rs index 3b609b4..2ae7941 100644 --- a/src/masks.rs +++ b/src/masks.rs @@ -1,9 +1,14 @@ +use once_cell::sync::Lazy; + // ============================================================================= // Date masks // ============================================================================= // Every mask is 7 days longer to handle cross-year weekly periods. +pub static MASKS: Lazy<Masks> = Lazy::new(|| Masks::new()); + +#[derive(Clone)] pub struct Masks { pub WDAY: Vec<usize>, pub M365: Vec<usize>, diff --git a/src/yearinfo.rs b/src/yearinfo.rs index 19a21a6..08aad23 100644 --- a/src/yearinfo.rs +++ b/src/yearinfo.rs @@ -1,4 +1,4 @@ -use crate::masks::Masks; +use crate::masks::MASKS; use crate::options::*; use chrono::prelude::*; use chrono::{DateTime, Duration}; @@ -39,7 +39,7 @@ pub struct BaseMasks { } fn base_year_masks(year: i32) -> BaseMasks { - let masks = Masks::new(); + let masks = MASKS.clone(); let firstyday = Utc.ymd(year, 1, 1).and_hms_milli(0, 0, 0, 0); let yearlen = get_year_len(year); let wday = get_weekday_val(&firstyday.weekday()) as usize; |