Skip to content

Commit 984a8ce

Browse files
committed
Replace once_cell by std::sync::OnceLock
1 parent b84ac85 commit 984a8ce

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ dependencies = [
11621162
"color-hex",
11631163
"document-features",
11641164
"emath",
1165-
"once_cell",
11661165
"serde",
11671166
]
11681167

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ home = "0.5.9"
8181
image = { version = "0.25", default-features = false }
8282
log = { version = "0.4", features = ["std"] }
8383
nohash-hasher = "0.2"
84-
once_cell = "1.19.0"
8584
parking_lot = "0.12"
8685
puffin = "0.19"
8786
puffin_http = "0.16"

crates/ecolor/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ default = []
3232

3333
[dependencies]
3434
emath.workspace = true
35-
once_cell.workspace = true
3635

3736
#! ### Optional dependencies
3837

crates/ecolor/src/color32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use once_cell::sync::Lazy;
2-
31
use crate::{fast_round, linear_f32_from_linear_u8, Rgba};
42

53
/// This format is used for space-efficient color representation (32 bits).
@@ -95,13 +93,15 @@ impl Color32 {
9593
/// From `sRGBA` WITHOUT premultiplied alpha.
9694
#[inline]
9795
pub fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Self {
96+
use std::sync::OnceLock;
9897
match a {
9998
// common-case optimization
10099
0 => Self::TRANSPARENT,
101100
// common-case optimization
102101
255 => Self::from_rgb(r, g, b),
103102
a => {
104-
static LOOKUP_TABLE: Lazy<[u8; 256 * 256]> = Lazy::new(|| {
103+
static LOOKUP_TABLE: OnceLock<[u8; 256 * 256]> = OnceLock::new();
104+
let lut = LOOKUP_TABLE.get_or_init(|| {
105105
use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8};
106106
core::array::from_fn(|i| {
107107
let [value, alpha] = (i as u16).to_ne_bytes();
@@ -111,8 +111,8 @@ impl Color32 {
111111
})
112112
});
113113

114-
let [r, g, b] = [r, g, b]
115-
.map(|value| LOOKUP_TABLE[usize::from(u16::from_ne_bytes([value, a]))]);
114+
let [r, g, b] =
115+
[r, g, b].map(|value| lut[usize::from(u16::from_ne_bytes([value, a]))]);
116116
Self::from_rgba_premultiplied(r, g, b, a)
117117
}
118118
}

0 commit comments

Comments
 (0)