From da03850eed36bbb766eb318e95ec156cfdaf6073 Mon Sep 17 00:00:00 2001
From: Xiliang Chen <xlchen1291@gmail.com>
Date: Sun, 25 Aug 2019 22:57:31 +1200
Subject: [PATCH] add Copy to Moment type (#3476)

* add Copy to Moment type

* bump version

* add Copy to support::Traits::Time::Moment and removed few clones
---
 substrate/node/runtime/src/lib.rs    | 2 +-
 substrate/srml/aura/src/lib.rs       | 4 ++--
 substrate/srml/democracy/src/lib.rs  | 4 ++--
 substrate/srml/staking/src/lib.rs    | 2 +-
 substrate/srml/support/src/traits.rs | 2 +-
 substrate/srml/timestamp/src/lib.rs  | 8 ++++----
 6 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs
index d1b9abd4cf1..0c5cdefd96f 100644
--- a/substrate/node/runtime/src/lib.rs
+++ b/substrate/node/runtime/src/lib.rs
@@ -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,
 };
 
diff --git a/substrate/srml/aura/src/lib.rs b/substrate/srml/aura/src/lib.rs
index e02a2e1f0a0..4df832912a5 100644
--- a/substrate/srml/aura/src/lib.rs
+++ b/substrate/srml/aura/src/lib.rs
@@ -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.");
diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs
index d4cfedc37bd..f1265438f29 100644
--- a/substrate/srml/democracy/src/lib.rs
+++ b/substrate/srml/democracy/src/lib.rs
@@ -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) {
diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs
index a4d1ed88abf..2e46d6b2b4a 100644
--- a/substrate/srml/staking/src/lib.rs
+++ b/substrate/srml/staking/src/lib.rs
@@ -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() {
diff --git a/substrate/srml/support/src/traits.rs b/substrate/srml/support/src/traits.rs
index cca9fd2b103..37262cdfcb5 100644
--- a/substrate/srml/support/src/traits.rs
+++ b/substrate/srml/support/src/traits.rs
@@ -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;
 }
diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs
index 78a741aff48..1b03b5b9af7 100644
--- a/substrate/srml/timestamp/src/lib.rs
+++ b/substrate/srml/timestamp/src/lib.rs
@@ -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);
-- 
GitLab