From fe1314dbc42da3331062c9348f7117b3585ad6bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 4 Feb 2020 02:28:11 +0100 Subject: [PATCH] fix couple of perf related clipyp warnings librustc: don't clone a type that is copy librustc_incremental: use faster vector initialization librustc_typeck: don't clone a type that is copy librustdoc: don't create a vector where a slice will do --- src/librustc/ty/mod.rs | 2 +- src/librustc_incremental/persist/file_format.rs | 3 +-- src/librustc_typeck/astconv.rs | 6 ++---- src/librustdoc/html/render.rs | 9 +-------- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index f417b907a38..9cfd64d6382 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1344,7 +1344,7 @@ pub trait ToPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(&self) -> Predicate<'tcx> { ty::Predicate::Trait( - ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value.clone() }), + ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, ) } diff --git a/src/librustc_incremental/persist/file_format.rs b/src/librustc_incremental/persist/file_format.rs index 7534b7e9ef4..5c72b049d97 100644 --- a/src/librustc_incremental/persist/file_format.rs +++ b/src/librustc_incremental/persist/file_format.rs @@ -90,8 +90,7 @@ pub fn read_file( let mut rustc_version_str_len = [0u8; 1]; file.read_exact(&mut rustc_version_str_len)?; let rustc_version_str_len = rustc_version_str_len[0] as usize; - let mut buffer = Vec::with_capacity(rustc_version_str_len); - buffer.resize(rustc_version_str_len, 0); + let mut buffer = vec![0; rustc_version_str_len]; file.read_exact(&mut buffer)?; if buffer != rustc_version().as_bytes() { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index c2123876b67..231aed48fb6 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1438,10 +1438,8 @@ fn conv_object_ty_poly_trait_ref( // Expand trait aliases recursively and check that only one regular (non-auto) trait // is used and no 'maybe' bounds are used. - let expanded_traits = traits::expand_trait_aliases( - tcx, - bounds.trait_bounds.iter().map(|&(a, b, _)| (a.clone(), b)), - ); + let expanded_traits = + traits::expand_trait_aliases(tcx, bounds.trait_bounds.iter().map(|&(a, b, _)| (a, b))); let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id())); if regular_traits.len() > 1 { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index c6706413942..a16f7248baa 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3629,14 +3629,7 @@ fn render_impl( for it in &i.inner_impl().items { if let clean::TypedefItem(ref tydef, _) = it.inner { write!(w, " "); - assoc_type( - w, - it, - &vec![], - Some(&tydef.type_), - AssocItemLink::Anchor(None), - "", - ); + assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None), ""); write!(w, ";"); } } -- 2.44.0