Skip to content

Commit 0e3454d

Browse files
committed
Once cell compression order
1 parent 8f43886 commit 0e3454d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

oma-refresh/src/config.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use aho_corasick::AhoCorasick;
55
#[cfg(feature = "apt")]
66
use oma_apt::config::{Config, ConfigTree};
77
use oma_fetch::CompressFile;
8+
use once_cell::sync::OnceCell;
89
use tracing::debug;
910

1011
use crate::{db::RefreshError, inrelease::ChecksumItem};
1112

13+
static COMPRESSION_ORDER: OnceCell<Vec<CompressFileWrapper>> = OnceCell::new();
14+
1215
#[derive(Debug, Eq, PartialEq)]
1316
struct CompressFileWrapper {
1417
compress_file: CompressFile,
@@ -55,11 +58,13 @@ impl PartialOrd for CompressFileWrapper {
5558
impl Ord for CompressFileWrapper {
5659
fn cmp(&self, other: &Self) -> Ordering {
5760
let config = Config::new();
58-
let t = config
59-
.get_compression_types()
60-
.iter()
61-
.map(|t| CompressFileWrapper::from(t.as_str()))
62-
.collect::<Vec<_>>();
61+
let t = COMPRESSION_ORDER.get_or_init(|| {
62+
config
63+
.get_compression_types()
64+
.iter()
65+
.map(|t| CompressFileWrapper::from(t.as_str()))
66+
.collect::<Vec<_>>()
67+
});
6368

6469
let self_pos = t.iter().position(|x| x == self).unwrap();
6570
let other_pos = t.iter().position(|x| x == other).unwrap();
@@ -71,10 +76,12 @@ impl Ord for CompressFileWrapper {
7176
#[cfg(not(feature = "apt"))]
7277
impl Ord for CompressFileWrapper {
7378
fn cmp(&self, other: &Self) -> Ordering {
74-
let t = vec!["zst", "xz", "bz2", "lzma", "gz", "lz4"]
75-
.into_iter()
76-
.map(CompressFileWrapper::from)
77-
.collect::<Vec<_>>();
79+
let t = COMPRESSION_ORDER.get_or_init(|| {
80+
vec!["zst", "xz", "bz2", "lzma", "gz", "lz4", "uncompressed"]
81+
.into_iter()
82+
.map(CompressFileWrapper::from)
83+
.collect::<Vec<_>>()
84+
});
7885

7986
let self_pos = t.iter().position(|x| x == self).unwrap();
8087
let other_pos = t.iter().position(|x| x == other).unwrap();

0 commit comments

Comments
 (0)