add Copy to Moment type (#3476)

* add Copy to Moment type

* bump version

* add Copy to support::Traits::Time::Moment and removed few clones
This commit is contained in:
Xiliang Chen
2019-08-25 22:57:31 +12:00
committed by Bastian Köcher
parent 672e62fe0f
commit da03850eed
6 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 151,
impl_version: 151,
impl_version: 152,
apis: RUNTIME_API_VERSIONS,
};
+2 -2
View File
@@ -258,7 +258,7 @@ impl<T: Trait> Module<T> {
fn on_timestamp_set(now: T::Moment, slot_duration: T::Moment) {
let last = Self::last();
<Self as Store>::LastTimestamp::put(now.clone());
<Self as Store>::LastTimestamp::put(now);
if last.is_zero() {
return;
@@ -266,7 +266,7 @@ impl<T: Trait> Module<T> {
assert!(!slot_duration.is_zero(), "Aura slot duration cannot be zero.");
let last_slot = last / slot_duration.clone();
let last_slot = last / slot_duration;
let cur_slot = now / slot_duration;
assert!(last_slot < cur_slot, "Only one block may be authored per slot.");
+2 -2
View File
@@ -946,12 +946,12 @@ impl<T: Trait> Module<T> {
if (now % T::LaunchPeriod::get()).is_zero() {
// Errors come from the queue being empty. we don't really care about that, and even if
// we did, there is nothing we can do here.
let _ = Self::launch_next(now.clone());
let _ = Self::launch_next(now);
}
// tally up votes for any expiring referenda.
for (index, info) in Self::maturing_referenda_at(now).into_iter() {
Self::bake_referendum(now.clone(), index, info)?;
Self::bake_referendum(now, index, info)?;
}
for (proposal, index) in <DispatchQueue<T>>::take(now).into_iter().filter_map(|x| x) {
+1 -1
View File
@@ -1179,7 +1179,7 @@ impl<T: Trait> Module<T> {
let rewards = CurrentEraRewards::take();
let now = T::Time::now();
let previous_era_start = <CurrentEraStart<T>>::mutate(|v| {
rstd::mem::replace(v, now.clone())
rstd::mem::replace(v, now)
});
let era_duration = now - previous_era_start;
if !era_duration.is_zero() {
+1 -1
View File
@@ -620,7 +620,7 @@ bitmask! {
}
pub trait Time {
type Moment: SimpleArithmetic + Codec + Clone + Default;
type Moment: SimpleArithmetic + Codec + Clone + Default + Copy;
fn now() -> Self::Moment;
}
+4 -4
View File
@@ -195,9 +195,9 @@ macro_rules! impl_timestamp_set {
);
( $($t:ident)* ) => {
impl<Moment: Clone, $($t: OnTimestampSet<Moment>),*> OnTimestampSet<Moment> for ($($t,)*) {
impl<Moment: Copy, $($t: OnTimestampSet<Moment>),*> OnTimestampSet<Moment> for ($($t,)*) {
fn on_timestamp_set(moment: Moment) {
$($t::on_timestamp_set(moment.clone());)*
$($t::on_timestamp_set(moment);)*
}
}
}
@@ -209,7 +209,7 @@ for_each_tuple!(impl_timestamp_set);
pub trait Trait: system::Trait {
/// Type used for expressing timestamp.
type Moment: Parameter + Default + SimpleArithmetic
+ Scale<Self::BlockNumber, Output = Self::Moment>;
+ Scale<Self::BlockNumber, Output = Self::Moment> + Copy;
/// Something which can be notified when the timestamp is set. Set this to `()` if not needed.
type OnTimestampSet: OnTimestampSet<Self::Moment>;
@@ -246,7 +246,7 @@ decl_module! {
Self::now().is_zero() || now >= Self::now() + T::MinimumPeriod::get(),
"Timestamp must increment by at least <MinimumPeriod> between sequential blocks"
);
<Self as Store>::Now::put(now.clone());
<Self as Store>::Now::put(now);
<Self as Store>::DidUpdate::put(true);
<T::OnTimestampSet as OnTimestampSet<_>>::on_timestamp_set(now);