From 446798f84ba0f0f9fe4c79a65256f5920ef2f4ac Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 8 Feb 2021 05:06:49 +0000 Subject: [PATCH 1/2] fix bootstrap --- src/bootstrap/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index f1a160250dbe1..0f5fcb4af400d 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1490,7 +1490,7 @@ impl<'a> Builder<'a> { for el in stack.iter().rev() { out += &format!("\t{:?}\n", el); } - panic!(out); + panic!("{}", out); } if let Some(out) = self.cache.get(&step) { self.verbose(&format!("{}c {:?}", " ".repeat(stack.len()), step)); From 010e194d6e7e0349518fb2bdb4c4a09a395dfce5 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 8 Feb 2021 05:01:02 +0000 Subject: [PATCH 2/2] Specialize slice::fill for Copy type and u8/i8/bool --- library/core/src/slice/mod.rs | 9 +---- library/core/src/slice/specialize.rs | 58 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 library/core/src/slice/specialize.rs diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 19a3b45e568c0..7db9c42921241 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -34,6 +34,7 @@ mod iter; mod raw; mod rotate; mod sort; +mod specialize; #[stable(feature = "rust1", since = "1.0.0")] pub use iter::{Chunks, ChunksMut, Windows}; @@ -2831,13 +2832,7 @@ impl [T] { where T: Clone, { - if let Some((last, elems)) = self.split_last_mut() { - for el in elems { - el.clone_from(&value); - } - - *last = value - } + specialize::SpecFill::spec_fill(self, value); } /// Fills `self` with elements returned by calling a closure repeatedly. diff --git a/library/core/src/slice/specialize.rs b/library/core/src/slice/specialize.rs new file mode 100644 index 0000000000000..16a9588989c85 --- /dev/null +++ b/library/core/src/slice/specialize.rs @@ -0,0 +1,58 @@ +use crate::ptr::write_bytes; + +pub(super) trait SpecFill { + fn spec_fill(&mut self, value: T); +} + +impl SpecFill for [T] { + default fn spec_fill(&mut self, value: T) { + if let Some((last, elems)) = self.split_last_mut() { + for el in elems { + el.clone_from(&value); + } + + *last = value + } + } +} + +impl SpecFill for [T] { + default fn spec_fill(&mut self, value: T) { + for item in self.iter_mut() { + *item = value; + } + } +} + +impl SpecFill for [u8] { + fn spec_fill(&mut self, value: u8) { + // SAFETY: this is slice of u8 + unsafe { + let ptr = self.as_mut_ptr(); + let len = self.len(); + write_bytes(ptr, value, len); + } + } +} + +impl SpecFill for [i8] { + fn spec_fill(&mut self, value: i8) { + // SAFETY: this is slice of i8 + unsafe { + let ptr = self.as_mut_ptr(); + let len = self.len(); + write_bytes(ptr, value as u8, len); + } + } +} + +impl SpecFill for [bool] { + fn spec_fill(&mut self, value: bool) { + // SAFETY: this is slice of bool + unsafe { + let ptr = self.as_mut_ptr(); + let len = self.len(); + write_bytes(ptr, value as u8, len); + } + } +}