From 984a8ce60d4533525828289f7a0c3f3bf3f964ea Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Mon, 9 Sep 2024 19:20:32 +0200 Subject: [PATCH] Replace once_cell by std::sync::OnceLock --- Cargo.lock | 1 - Cargo.toml | 1 - crates/ecolor/Cargo.toml | 1 - crates/ecolor/src/color32.rs | 10 +++++----- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5dc8b860205..f11f4d03164 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1162,7 +1162,6 @@ dependencies = [ "color-hex", "document-features", "emath", - "once_cell", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index c5cd582fc56..90f4d7c17c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,6 @@ home = "0.5.9" image = { version = "0.25", default-features = false } log = { version = "0.4", features = ["std"] } nohash-hasher = "0.2" -once_cell = "1.19.0" parking_lot = "0.12" puffin = "0.19" puffin_http = "0.16" diff --git a/crates/ecolor/Cargo.toml b/crates/ecolor/Cargo.toml index 92efbbcbcaf..c1a10070c03 100644 --- a/crates/ecolor/Cargo.toml +++ b/crates/ecolor/Cargo.toml @@ -32,7 +32,6 @@ default = [] [dependencies] emath.workspace = true -once_cell.workspace = true #! ### Optional dependencies diff --git a/crates/ecolor/src/color32.rs b/crates/ecolor/src/color32.rs index 9103a9737dd..9025b6ee548 100644 --- a/crates/ecolor/src/color32.rs +++ b/crates/ecolor/src/color32.rs @@ -1,5 +1,3 @@ -use once_cell::sync::Lazy; - use crate::{fast_round, linear_f32_from_linear_u8, Rgba}; /// This format is used for space-efficient color representation (32 bits). @@ -95,13 +93,15 @@ impl Color32 { /// From `sRGBA` WITHOUT premultiplied alpha. #[inline] pub fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Self { + use std::sync::OnceLock; match a { // common-case optimization 0 => Self::TRANSPARENT, // common-case optimization 255 => Self::from_rgb(r, g, b), a => { - static LOOKUP_TABLE: Lazy<[u8; 256 * 256]> = Lazy::new(|| { + static LOOKUP_TABLE: OnceLock<[u8; 256 * 256]> = OnceLock::new(); + let lut = LOOKUP_TABLE.get_or_init(|| { use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8}; core::array::from_fn(|i| { let [value, alpha] = (i as u16).to_ne_bytes(); @@ -111,8 +111,8 @@ impl Color32 { }) }); - let [r, g, b] = [r, g, b] - .map(|value| LOOKUP_TABLE[usize::from(u16::from_ne_bytes([value, a]))]); + let [r, g, b] = + [r, g, b].map(|value| lut[usize::from(u16::from_ne_bytes([value, a]))]); Self::from_rgba_premultiplied(r, g, b, a) } }