Skip to content

Commit

Permalink
Remove unnecessary Clone trait bounds on CountedStorageMap (paritytec…
Browse files Browse the repository at this point in the history
…h#12402)

* Remove unnecessary Clone trait bounds on CountedStorageMap

* cargo fmt
  • Loading branch information
KiChjang authored and ark0f committed Feb 27, 2023
1 parent 795c98d commit 8c84bb0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions frame/support/src/storage/types/counted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,23 @@ where
}

/// Store a value to be associated with the given key from the map.
pub fn insert<KeyArg: EncodeLike<Key> + Clone, ValArg: EncodeLike<Value>>(
key: KeyArg,
val: ValArg,
) {
pub fn insert<KeyArg: EncodeLike<Key>, ValArg: EncodeLike<Value>>(key: KeyArg, val: ValArg) {
if !<Self as MapWrapper>::Map::contains_key(Ref::from(&key)) {
CounterFor::<Prefix>::mutate(|value| value.saturating_inc());
}
<Self as MapWrapper>::Map::insert(key, val)
}

/// Remove the value under a key.
pub fn remove<KeyArg: EncodeLike<Key> + Clone>(key: KeyArg) {
pub fn remove<KeyArg: EncodeLike<Key>>(key: KeyArg) {
if <Self as MapWrapper>::Map::contains_key(Ref::from(&key)) {
CounterFor::<Prefix>::mutate(|value| value.saturating_dec());
}
<Self as MapWrapper>::Map::remove(key)
}

/// Mutate the value under a key.
pub fn mutate<KeyArg: EncodeLike<Key> + Clone, R, F: FnOnce(&mut QueryKind::Query) -> R>(
pub fn mutate<KeyArg: EncodeLike<Key>, R, F: FnOnce(&mut QueryKind::Query) -> R>(
key: KeyArg,
f: F,
) -> R {
Expand All @@ -173,7 +170,7 @@ where
/// Mutate the item, only if an `Ok` value is returned.
pub fn try_mutate<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<Key> + Clone,
KeyArg: EncodeLike<Key>,
F: FnOnce(&mut QueryKind::Query) -> Result<R, E>,
{
Self::try_mutate_exists(key, |option_value_ref| {
Expand All @@ -187,7 +184,7 @@ where
}

/// Mutate the value under a key. Deletes the item if mutated to a `None`.
pub fn mutate_exists<KeyArg: EncodeLike<Key> + Clone, R, F: FnOnce(&mut Option<Value>) -> R>(
pub fn mutate_exists<KeyArg: EncodeLike<Key>, R, F: FnOnce(&mut Option<Value>) -> R>(
key: KeyArg,
f: F,
) -> R {
Expand All @@ -200,7 +197,7 @@ where
/// or if the storage item does not exist (`None`), independent of the `QueryType`.
pub fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<Key> + Clone,
KeyArg: EncodeLike<Key>,
F: FnOnce(&mut Option<Value>) -> Result<R, E>,
{
<Self as MapWrapper>::Map::try_mutate_exists(key, |option_value| {
Expand All @@ -222,7 +219,7 @@ where
}

/// Take the value under a key.
pub fn take<KeyArg: EncodeLike<Key> + Clone>(key: KeyArg) -> QueryKind::Query {
pub fn take<KeyArg: EncodeLike<Key>>(key: KeyArg) -> QueryKind::Query {
let removed_value = <Self as MapWrapper>::Map::mutate_exists(key, |value| value.take());
if removed_value.is_some() {
CounterFor::<Prefix>::mutate(|value| value.saturating_dec());
Expand All @@ -240,7 +237,7 @@ where
/// `[item]`. Any default value set for the storage item will be ignored on overwrite.
pub fn append<Item, EncodeLikeItem, EncodeLikeKey>(key: EncodeLikeKey, item: EncodeLikeItem)
where
EncodeLikeKey: EncodeLike<Key> + Clone,
EncodeLikeKey: EncodeLike<Key>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageAppend<Item>,
Expand Down Expand Up @@ -355,7 +352,7 @@ where
/// Is only available if `Value` of the storage implements [`StorageTryAppend`].
pub fn try_append<KArg, Item, EncodeLikeItem>(key: KArg, item: EncodeLikeItem) -> Result<(), ()>
where
KArg: EncodeLike<Key> + Clone,
KArg: EncodeLike<Key>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
Value: StorageTryAppend<Item>,
Expand Down

0 comments on commit 8c84bb0

Please sign in to comment.