Skip to content

Remove size_of == 1 case from fill specialization. #87892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions library/core/src/slice/specialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use crate::mem::{size_of, transmute_copy};
use crate::ptr::write_bytes;

pub(super) trait SpecFill<T> {
fn spec_fill(&mut self, value: T);
}
Expand All @@ -19,17 +16,8 @@ impl<T: Clone> SpecFill<T> for [T] {

impl<T: Copy> SpecFill<T> for [T] {
fn spec_fill(&mut self, value: T) {
if size_of::<T>() == 1 {
// SAFETY: The size_of check above ensures that values are 1 byte wide, as required
// for the transmute and write_bytes
unsafe {
let value: u8 = transmute_copy(&value);
write_bytes(self.as_mut_ptr(), value, self.len());
}
} else {
for item in self.iter_mut() {
*item = value;
}
for item in self.iter_mut() {
*item = value;
}
}
}