From a32a3b8ccadb873d77e658dd31b071f80db7ab43 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 17 Mar 2023 09:13:41 +0000 Subject: [PATCH] Construct HashMaps in provider database from array This saves 450 lines according to `cargo llvm-lines --release`. --- scripts/create-provider-data-rs.py | 8 ++++---- src/provider/data.rs | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/scripts/create-provider-data-rs.py b/scripts/create-provider-data-rs.py index ea5d291ee..57f92428e 100755 --- a/scripts/create-provider-data-rs.py +++ b/scripts/create-provider-data-rs.py @@ -220,13 +220,13 @@ if __name__ == "__main__": process_dir(Path(sys.argv[1])) - out_all += "pub(crate) static PROVIDER_DATA: Lazy> = Lazy::new(|| [\n" + out_all += "pub(crate) static PROVIDER_DATA: Lazy> = Lazy::new(|| HashMap::from([\n" out_all += out_domains - out_all += "].iter().copied().collect());\n\n" + out_all += "]));\n\n" - out_all += "pub(crate) static PROVIDER_IDS: Lazy> = Lazy::new(|| [\n" + out_all += "pub(crate) static PROVIDER_IDS: Lazy> = Lazy::new(|| HashMap::from([\n" out_all += out_ids - out_all += "].iter().copied().collect());\n\n" + out_all += "]));\n\n" if len(sys.argv) < 3: now = datetime.datetime.utcnow() diff --git a/src/provider/data.rs b/src/provider/data.rs index f7736c6e9..8ca9d91e9 100644 --- a/src/provider/data.rs +++ b/src/provider/data.rs @@ -1513,7 +1513,7 @@ static P_ZOHO: Lazy = Lazy::new(|| Provider { }); pub(crate) static PROVIDER_DATA: Lazy> = Lazy::new(|| { - [ + HashMap::from([ ("163.com", &*P_163), ("aktivix.org", &*P_AKTIVIX_ORG), ("aol.com", &*P_AOL), @@ -1875,14 +1875,11 @@ pub(crate) static PROVIDER_DATA: Lazy> ("zohomail.eu", &*P_ZOHO), ("zohomail.com", &*P_ZOHO), ("zoho.com", &*P_ZOHO), - ] - .iter() - .copied() - .collect() + ]) }); pub(crate) static PROVIDER_IDS: Lazy> = Lazy::new(|| { - [ + HashMap::from([ ("163", &*P_163), ("aktivix.org", &*P_AKTIVIX_ORG), ("aol", &*P_AOL), @@ -1945,10 +1942,7 @@ pub(crate) static PROVIDER_IDS: Lazy> = ("yggmail", &*P_YGGMAIL), ("ziggo.nl", &*P_ZIGGO_NL), ("zoho", &*P_ZOHO), - ] - .iter() - .copied() - .collect() + ]) }); pub static PROVIDER_UPDATED: Lazy =