Skip to content

Commit b78816a

Browse files
committed
Avoid using once_cell
1 parent 755f9c0 commit b78816a

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ arrayvec = "0.7.4"
3535
rgb = { version = "0.8.47", default-features = false, features = ["bytemuck"] }
3636
rayon = { version = "1.10.0", optional = true }
3737
thread_local = { version = "1.1.8", optional = true }
38-
once_cell = "1.19.0"
3938

4039
[dev-dependencies]
4140
lodepng = "3.10"

src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ impl fmt::Display for Error {
4949
}
5050
}
5151

52+
impl From<core::convert::Infallible> for Error {
53+
fn from(e: core::convert::Infallible) -> Self {
54+
match e {}
55+
}
56+
}
57+
5258
impl From<TryReserveError> for Error {
5359
#[cold]
5460
fn from(_: TryReserveError) -> Self {

src/rayoff.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::slice::ChunksMut;
2-
use once_cell::unsync::OnceCell;
2+
use core::cell::OnceCell;
33

44
pub(crate) struct ThreadLocal<T>(OnceCell<T>);
55

@@ -15,8 +15,9 @@ impl<T> ThreadLocal<T> {
1515
}
1616

1717
#[inline(always)]
18-
pub fn get_or_try<E>(&self, f: impl FnOnce() -> Result<T, E>) -> Result<&T, E> {
19-
self.0.get_or_try_init(f)
18+
pub fn get_or_try<E>(&self, f: impl FnOnce() -> Result<T, E>) -> Result<&T, core::convert::Infallible> {
19+
// https://github.com/rust-lang/rust/issues/109737
20+
Ok(self.0.get_or_init(move || f().ok().unwrap()))
2021
}
2122
}
2223

@@ -40,19 +41,19 @@ impl<T> FakeRayonIter for T where Self: Sized {
4041
}
4142

4243
pub(crate) trait FakeRayonIntoIter<T> {
43-
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T>;
44+
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T>;
4445
}
4546

4647
impl<'a, T> FakeRayonIntoIter<T> for &'a mut [T] {
4748
#[inline(always)]
48-
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T> {
49+
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> {
4950
self.chunks_mut(chunk_size)
5051
}
5152
}
5253

5354
impl<'a, T> FakeRayonIntoIter<T> for Box<[T]> {
5455
#[inline(always)]
55-
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T> {
56+
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> {
5657
self.chunks_mut(chunk_size)
5758
}
5859
}

src/remap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub(crate) fn remap_to_palette<'x, 'b: 'x>(px: &mut DynamicRows, background: Opt
5757

5858
let remapping_error = output_pixels.rows_mut().enumerate().par_bridge().map(|(row, output_pixels_row)| {
5959
let mut remapping_error = 0.;
60+
#[allow(irrefutable_let_patterns)]
6061
let Ok(tls_res) = tls.get_or_try(per_thread_buffers) else { return f64::NAN };
6162
let (kmeans, temp_row, temp_row_f, temp_row_f_bg) = &mut *tls_res.0.borrow_mut();
6263

0 commit comments

Comments
 (0)