Skip to content

Commit dba6059

Browse files
authored
chore: Use once_cell to replace lazy_static (#443)
* chore: Use once_cell to replace lazy_static Signed-off-by: Xuanwo <[email protected]> * Format toml Signed-off-by: Xuanwo <[email protected]> --------- Signed-off-by: Xuanwo <[email protected]>
1 parent 8562708 commit dba6059

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ iceberg = { version = "0.2.0", path = "./crates/iceberg" }
6262
iceberg-catalog-rest = { version = "0.2.0", path = "./crates/catalog/rest" }
6363
iceberg-catalog-hms = { version = "0.2.0", path = "./crates/catalog/hms" }
6464
itertools = "0.13"
65-
lazy_static = "1"
6665
log = "^0.4"
6766
mockito = "^1"
6867
murmur3 = "0.5.2"

crates/iceberg/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ derive_builder = { workspace = true }
5959
fnv = { workspace = true }
6060
futures = { workspace = true }
6161
itertools = { workspace = true }
62-
lazy_static = { workspace = true }
6362
murmur3 = { workspace = true }
6463
once_cell = { workspace = true }
6564
opendal = { workspace = true }

crates/iceberg/src/spec/datatypes.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,37 @@ pub(crate) const MAX_DECIMAL_BYTES: u32 = 24;
4141
pub(crate) const MAX_DECIMAL_PRECISION: u32 = 38;
4242

4343
mod _decimal {
44-
use lazy_static::lazy_static;
44+
use once_cell::sync::Lazy;
4545

4646
use crate::spec::{MAX_DECIMAL_BYTES, MAX_DECIMAL_PRECISION};
4747

48-
lazy_static! {
49-
// Max precision of bytes, starts from 1
50-
pub(super) static ref MAX_PRECISION: [u32; MAX_DECIMAL_BYTES as usize] = {
51-
let mut ret: [u32; 24] = [0; 24];
52-
for (i, prec) in ret.iter_mut().enumerate() {
53-
*prec = 2f64.powi((8 * (i + 1) - 1) as i32).log10().floor() as u32;
54-
}
48+
// Max precision of bytes, starts from 1
49+
pub(super) static MAX_PRECISION: Lazy<[u32; MAX_DECIMAL_BYTES as usize]> = Lazy::new(|| {
50+
let mut ret: [u32; 24] = [0; 24];
51+
for (i, prec) in ret.iter_mut().enumerate() {
52+
*prec = 2f64.powi((8 * (i + 1) - 1) as i32).log10().floor() as u32;
53+
}
5554

56-
ret
57-
};
55+
ret
56+
});
5857

59-
// Required bytes of precision, starts from 1
60-
pub(super) static ref REQUIRED_LENGTH: [u32; MAX_DECIMAL_PRECISION as usize] = {
61-
let mut ret: [u32; MAX_DECIMAL_PRECISION as usize] = [0; MAX_DECIMAL_PRECISION as usize];
58+
// Required bytes of precision, starts from 1
59+
pub(super) static REQUIRED_LENGTH: Lazy<[u32; MAX_DECIMAL_PRECISION as usize]> =
60+
Lazy::new(|| {
61+
let mut ret: [u32; MAX_DECIMAL_PRECISION as usize] =
62+
[0; MAX_DECIMAL_PRECISION as usize];
6263

6364
for (i, required_len) in ret.iter_mut().enumerate() {
6465
for j in 0..MAX_PRECISION.len() {
65-
if MAX_PRECISION[j] >= ((i+1) as u32) {
66-
*required_len = (j+1) as u32;
66+
if MAX_PRECISION[j] >= ((i + 1) as u32) {
67+
*required_len = (j + 1) as u32;
6768
break;
6869
}
6970
}
7071
}
7172

7273
ret
73-
};
74-
75-
}
74+
});
7675
}
7776

7877
#[derive(Debug, PartialEq, Eq, Clone)]

0 commit comments

Comments
 (0)