@@ -5,10 +5,13 @@ use aho_corasick::AhoCorasick;
5
5
#[ cfg( feature = "apt" ) ]
6
6
use oma_apt:: config:: { Config , ConfigTree } ;
7
7
use oma_fetch:: CompressFile ;
8
+ use once_cell:: sync:: OnceCell ;
8
9
use tracing:: debug;
9
10
10
11
use crate :: { db:: RefreshError , inrelease:: ChecksumItem } ;
11
12
13
+ static COMPRESSION_ORDER : OnceCell < Vec < CompressFileWrapper > > = OnceCell :: new ( ) ;
14
+
12
15
#[ derive( Debug , Eq , PartialEq ) ]
13
16
struct CompressFileWrapper {
14
17
compress_file : CompressFile ,
@@ -55,11 +58,13 @@ impl PartialOrd for CompressFileWrapper {
55
58
impl Ord for CompressFileWrapper {
56
59
fn cmp ( & self , other : & Self ) -> Ordering {
57
60
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
+ } ) ;
63
68
64
69
let self_pos = t. iter ( ) . position ( |x| x == self ) . unwrap ( ) ;
65
70
let other_pos = t. iter ( ) . position ( |x| x == other) . unwrap ( ) ;
@@ -71,10 +76,12 @@ impl Ord for CompressFileWrapper {
71
76
#[ cfg( not( feature = "apt" ) ) ]
72
77
impl Ord for CompressFileWrapper {
73
78
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
+ } ) ;
78
85
79
86
let self_pos = t. iter ( ) . position ( |x| x == self ) . unwrap ( ) ;
80
87
let other_pos = t. iter ( ) . position ( |x| x == other) . unwrap ( ) ;
0 commit comments