mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Improve overall performance (#6699)
* Improve overall performance * Clean up code Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove needless :: Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove needless :: Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -1092,7 +1092,7 @@ impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
|
||||
|
||||
// defensive only: overflow should never happen, however in case it does, then this
|
||||
// operation is a no-op.
|
||||
account.free = account.free.checked_add(&value).ok_or(Self::PositiveImbalance::zero())?;
|
||||
account.free = account.free.checked_add(&value).ok_or_else(|| Self::PositiveImbalance::zero())?;
|
||||
|
||||
Ok(PositiveImbalance::new(value))
|
||||
}).unwrap_or_else(|x| x)
|
||||
@@ -1153,7 +1153,7 @@ impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
|
||||
};
|
||||
account.free = value;
|
||||
Ok(imbalance)
|
||||
}).unwrap_or(SignedImbalance::Positive(Self::PositiveImbalance::zero()))
|
||||
}).unwrap_or_else(|_| SignedImbalance::Positive(Self::PositiveImbalance::zero()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -801,7 +801,7 @@ where
|
||||
|
||||
fn rent_allowance(&self) -> BalanceOf<T> {
|
||||
storage::rent_allowance::<T>(&self.ctx.self_account)
|
||||
.unwrap_or(<BalanceOf<T>>::max_value()) // Must never be triggered actually
|
||||
.unwrap_or_else(|_| <BalanceOf<T>>::max_value()) // Must never be triggered actually
|
||||
}
|
||||
|
||||
fn block_number(&self) -> T::BlockNumber { self.block_number }
|
||||
|
||||
@@ -648,7 +648,7 @@ impl<T: Trait> Module<T> {
|
||||
let cfg = Config::preload();
|
||||
let vm = WasmVm::new(&cfg.schedule);
|
||||
let loader = WasmLoader::new(&cfg.schedule);
|
||||
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
|
||||
func(&mut ctx, gas_meter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ fn compute_fee_per_block<T: Trait>(
|
||||
|
||||
effective_storage_size
|
||||
.checked_mul(&T::RentByteFee::get())
|
||||
.unwrap_or(<BalanceOf<T>>::max_value())
|
||||
.unwrap_or_else(|| <BalanceOf<T>>::max_value())
|
||||
}
|
||||
|
||||
/// Returns amount of funds available to consume by rent mechanism.
|
||||
@@ -179,7 +179,7 @@ fn consider_case<T: Trait>(
|
||||
|
||||
let dues = fee_per_block
|
||||
.checked_mul(&blocks_passed.saturated_into::<u32>().into())
|
||||
.unwrap_or(<BalanceOf<T>>::max_value());
|
||||
.unwrap_or_else(|| <BalanceOf<T>>::max_value());
|
||||
let insufficient_rent = rent_budget < dues;
|
||||
|
||||
// If the rent payment cannot be withdrawn due to locks on the account balance, then evict the
|
||||
|
||||
@@ -607,7 +607,7 @@ decl_module! {
|
||||
// returns NoMember error in case of error.
|
||||
let _ = Self::remove_and_replace_member(&who)?;
|
||||
T::Currency::unreserve(&who, T::CandidacyBond::get());
|
||||
Self::deposit_event(RawEvent::MemberRenounced(who.clone()));
|
||||
Self::deposit_event(RawEvent::MemberRenounced(who));
|
||||
},
|
||||
Renouncing::RunnerUp => {
|
||||
let mut runners_up_with_stake = Self::runners_up();
|
||||
@@ -1002,7 +1002,7 @@ impl<T: Trait> Module<T> {
|
||||
);
|
||||
T::ChangeMembers::change_members_sorted(
|
||||
&incoming,
|
||||
&outgoing.clone(),
|
||||
&outgoing,
|
||||
&new_members_ids,
|
||||
);
|
||||
T::ChangeMembers::set_prime(prime);
|
||||
|
||||
@@ -295,12 +295,12 @@ decl_module! {
|
||||
ensure!(!other_signatories.is_empty(), Error::<T>::TooFewSignatories);
|
||||
let other_signatories_len = other_signatories.len();
|
||||
ensure!(other_signatories_len < max_sigs, Error::<T>::TooManySignatories);
|
||||
let signatories = Self::ensure_sorted_and_insert(other_signatories, who.clone())?;
|
||||
let signatories = Self::ensure_sorted_and_insert(other_signatories, who)?;
|
||||
|
||||
let id = Self::multi_account_id(&signatories, 1);
|
||||
|
||||
let call_len = call.using_encoded(|c| c.len());
|
||||
let result = call.dispatch(RawOrigin::Signed(id.clone()).into());
|
||||
let result = call.dispatch(RawOrigin::Signed(id).into());
|
||||
|
||||
result.map(|post_dispatch_info| post_dispatch_info.actual_weight
|
||||
.map(|actual_weight| weight_of::as_multi_threshold_1::<T>(
|
||||
|
||||
@@ -257,7 +257,7 @@ benchmarks! {
|
||||
.flat_map(|reporter| vec![
|
||||
frame_system::Event::<T>::NewAccount(reporter.clone()).into(),
|
||||
<T as BalancesTrait>::Event::from(
|
||||
pallet_balances::Event::<T>::Endowed(reporter.clone(), (reward_amount / r).into())
|
||||
pallet_balances::Event::<T>::Endowed(reporter, (reward_amount / r).into())
|
||||
).into()
|
||||
]);
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ decl_module! {
|
||||
// if there is already an element with `score`, we insert
|
||||
// right before that. if not, the search returns a location
|
||||
// where we can insert while maintaining order.
|
||||
let item = (who.clone(), Some(score.clone()));
|
||||
let item = (who, Some(score.clone()));
|
||||
let location = pool
|
||||
.binary_search_by_key(
|
||||
&Reverse(score),
|
||||
|
||||
@@ -162,7 +162,7 @@ fn main() {
|
||||
match mode {
|
||||
Mode::WeakerSubmission => {
|
||||
assert_eq!(
|
||||
call.dispatch_bypass_filter(origin.clone().into()).unwrap_err().error,
|
||||
call.dispatch_bypass_filter(origin.into()).unwrap_err().error,
|
||||
DispatchError::Module {
|
||||
index: 0,
|
||||
error: 16,
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn create_validator_with_nominators<T: Trait>(
|
||||
let validator_prefs = ValidatorPrefs {
|
||||
commission: Perbill::from_percent(50),
|
||||
};
|
||||
Staking::<T>::validate(RawOrigin::Signed(v_controller.clone()).into(), validator_prefs)?;
|
||||
Staking::<T>::validate(RawOrigin::Signed(v_controller).into(), validator_prefs)?;
|
||||
let stash_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(v_stash.clone());
|
||||
|
||||
points_total += 10;
|
||||
@@ -375,7 +375,7 @@ benchmarks! {
|
||||
for _ in 0 .. l {
|
||||
staking_ledger.unlocking.push(unlock_chunk.clone())
|
||||
}
|
||||
Ledger::<T>::insert(controller.clone(), staking_ledger.clone());
|
||||
Ledger::<T>::insert(controller, staking_ledger);
|
||||
let slash_amount = T::Currency::minimum_balance() * 10.into();
|
||||
let balance_before = T::Currency::free_balance(&stash);
|
||||
}: {
|
||||
|
||||
@@ -1626,7 +1626,7 @@ decl_module! {
|
||||
let era = Self::current_era().unwrap_or(0) + T::BondingDuration::get();
|
||||
ledger.unlocking.push(UnlockChunk { value, era });
|
||||
Self::update_ledger(&controller, &ledger);
|
||||
Self::deposit_event(RawEvent::Unbonded(ledger.stash.clone(), value));
|
||||
Self::deposit_event(RawEvent::Unbonded(ledger.stash, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ fn slash_nominators<T: Trait>(
|
||||
let mut era_slash = <Module<T> as Store>::NominatorSlashInEra::get(
|
||||
&slash_era,
|
||||
stash,
|
||||
).unwrap_or(Zero::zero());
|
||||
).unwrap_or_else(|| Zero::zero());
|
||||
|
||||
era_slash += own_slash_difference;
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ pub fn get_weak_solution<T: Trait>(
|
||||
|
||||
// self stake
|
||||
<Validators<T>>::iter().for_each(|(who, _p)| {
|
||||
*backing_stake_of.entry(who.clone()).or_insert(Zero::zero()) +=
|
||||
*backing_stake_of.entry(who.clone()).or_insert_with(|| Zero::zero()) +=
|
||||
<Module<T>>::slashable_balance_of(&who)
|
||||
});
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ impl StorageLineDefExt {
|
||||
StorageLineTypeDef::DoubleMap(map) => map.value.clone(),
|
||||
};
|
||||
let is_option = ext::extract_type_option(&query_type).is_some();
|
||||
let value_type = ext::extract_type_option(&query_type).unwrap_or(query_type.clone());
|
||||
let value_type = ext::extract_type_option(&query_type).unwrap_or_else(|| query_type.clone());
|
||||
|
||||
let module_runtime_generic = &def.module_runtime_generic;
|
||||
let module_runtime_trait = &def.module_runtime_trait;
|
||||
@@ -328,7 +328,7 @@ impl StorageLineDefExt {
|
||||
|
||||
pub enum StorageLineTypeDef {
|
||||
Map(MapDef),
|
||||
DoubleMap(DoubleMapDef),
|
||||
DoubleMap(Box<DoubleMapDef>),
|
||||
Simple(syn::Type),
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ impl_parse_for_opt!(DeclStorageBuild => keyword::build);
|
||||
#[derive(ToTokens, Debug)]
|
||||
enum DeclStorageType {
|
||||
Map(DeclStorageMap),
|
||||
DoubleMap(DeclStorageDoubleMap),
|
||||
DoubleMap(Box<DeclStorageDoubleMap>),
|
||||
Simple(syn::Type),
|
||||
}
|
||||
|
||||
@@ -478,13 +478,13 @@ fn parse_storage_line_defs(
|
||||
}
|
||||
),
|
||||
DeclStorageType::DoubleMap(map) => super::StorageLineTypeDef::DoubleMap(
|
||||
super::DoubleMapDef {
|
||||
Box::new(super::DoubleMapDef {
|
||||
hasher1: map.hasher1.inner.ok_or_else(no_hasher_error)?.into(),
|
||||
hasher2: map.hasher2.inner.ok_or_else(no_hasher_error)?.into(),
|
||||
key1: map.key1,
|
||||
key2: map.key2,
|
||||
value: map.value,
|
||||
}
|
||||
})
|
||||
),
|
||||
DeclStorageType::Simple(expr) => super::StorageLineTypeDef::Simple(expr),
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ pub(crate) fn fields_idents(
|
||||
fields: impl Iterator<Item = syn::Field>,
|
||||
) -> impl Iterator<Item = proc_macro2::TokenStream> {
|
||||
fields.enumerate().map(|(ix, field)| {
|
||||
field.ident.clone().map(|i| quote!{#i}).unwrap_or_else(|| {
|
||||
field.ident.map(|i| quote!{#i}).unwrap_or_else(|| {
|
||||
let f_ix: syn::Ident = syn::Ident::new(&format!("f_{}", ix), Span::call_site());
|
||||
quote!( #f_ix )
|
||||
})
|
||||
@@ -41,7 +41,7 @@ pub(crate) fn fields_access(
|
||||
fields: impl Iterator<Item = syn::Field>,
|
||||
) -> impl Iterator<Item = proc_macro2::TokenStream> {
|
||||
fields.enumerate().map(|(ix, field)| {
|
||||
field.ident.clone().map(|i| quote!( #i )).unwrap_or_else(|| {
|
||||
field.ident.map(|i| quote!( #i )).unwrap_or_else(|| {
|
||||
let f_ix: syn::Index = syn::Index {
|
||||
index: ix as u32,
|
||||
span: Span::call_site(),
|
||||
|
||||
@@ -185,7 +185,7 @@ impl<T: SigningTypes, C: AppCrypto<T::Public, T::Signature>, X> Signer<T, C, X>
|
||||
let generic_public = C::GenericPublic::from(key);
|
||||
let public = generic_public.into();
|
||||
let account_id = public.clone().into_account();
|
||||
Account::new(index, account_id, public.clone())
|
||||
Account::new(index, account_id, public)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user