Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Clone bound for graphics::Cache::clear #2575

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions graphics/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Cache computations and efficiently reuse them.
use std::cell::RefCell;
use std::fmt;
use std::mem;
use std::sync::atomic::{self, AtomicU64};

/// A simple cache that stores generated values to avoid recomputation.
Expand Down Expand Up @@ -58,18 +59,18 @@ impl<T> Cache<T> {
}

/// Clears the [`Cache`].
pub fn clear(&self)
where
T: Clone,
{
use std::ops::Deref;
pub fn clear(&self) {
let mut state = self.state.borrow_mut();

let previous =
mem::replace(&mut *state, State::Empty { previous: None });

let previous = match self.state.borrow().deref() {
State::Empty { previous } => previous.clone(),
State::Filled { current } => Some(current.clone()),
let previous = match previous {
State::Empty { previous } => previous,
State::Filled { current } => Some(current),
};

*self.state.borrow_mut() = State::Empty { previous };
*state = State::Empty { previous };
}
}

Expand Down
Loading