diff options
author | 2024-09-13 02:02:49 +0200 | |
---|---|---|
committer | 2024-09-13 02:02:49 +0200 | |
commit | 62b4da87d188198d4c639f04db5275ac3d6fa5da (patch) | |
tree | b4911f98b5e52d6a4ce14afa4b8333c03e705968 /graphics | |
parent | c66355f289b1e389dc7de045d6ddfe75803302d1 (diff) | |
parent | e140c03b9b5e2f9e58a230a51646af5c3f9e85e5 (diff) | |
download | iced-62b4da87d188198d4c639f04db5275ac3d6fa5da.tar.gz iced-62b4da87d188198d4c639f04db5275ac3d6fa5da.tar.bz2 iced-62b4da87d188198d4c639f04db5275ac3d6fa5da.zip |
Merge pull request #2575 from m4rch3n1ng/rm-clone-trait-bound
remove unnecessary Clone trait bound for Cache::clear
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/src/cache.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/graphics/src/cache.rs b/graphics/src/cache.rs index bbba79eb..7db80a01 100644 --- a/graphics/src/cache.rs +++ b/graphics/src/cache.rs @@ -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. @@ -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 }; } } |