From 89b4848ec21dbdbeadfd84ab46956379dbfd0747 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 May 2020 21:12:00 -0700 Subject: [PATCH] Skip init on clone The cloned buffer's content is not observable until written into, so there is no need to keep it identical to the old buffer's content. --- src/buffer/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index b62e188..d524de6 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -21,7 +21,6 @@ const NEG_INFINITY: &'static str = "-inf"; /// let printed = buffer.format_finite(1.234); /// assert_eq!(printed, "1.234"); /// ``` -#[derive(Copy, Clone)] pub struct Buffer { #[cfg(maybe_uninit)] bytes: [MaybeUninit; 24], @@ -93,6 +92,15 @@ impl Buffer { } } +impl Copy for Buffer {} + +impl Clone for Buffer { + #[inline] + fn clone(&self) -> Self { + Buffer::new() + } +} + impl Default for Buffer { #[inline] #[cfg_attr(feature = "no-panic", no_panic)]