Skip to content

Use .copy_from_slice() where applicable #31914

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
Feb 27, 2016
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/libcore/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'a> Part<'a> {
}
}
Part::Copy(buf) => {
out[..buf.len()].clone_from_slice(buf);
out[..buf.len()].copy_from_slice(buf);
}
}
Some(len)
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<'a> Formatted<'a> {
/// (It may still leave partially written bytes in the buffer; do not rely on that.)
pub fn write(&self, out: &mut [u8]) -> Option<usize> {
if out.len() < self.sign.len() { return None; }
out[..self.sign.len()].clone_from_slice(self.sign);
out[..self.sign.len()].copy_from_slice(self.sign);

let mut written = self.sign.len();
for part in self.parts {
Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#![feature(box_syntax)]
#![feature(cell_extras)]
#![feature(const_fn)]
#![feature(copy_from_slice)]
#![feature(core_float)]
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn check_exact<F, T>(mut f: F, v: T, vstr: &str, expected: &[u8], expectedk: i16

// check significant digits
for i in 1..cut.unwrap_or(expected.len() - 1) {
expected_[..i].clone_from_slice(&expected[..i]);
expected_[..i].copy_from_slice(&expected[..i]);
let mut expectedk_ = expectedk;
if expected[i] >= b'5' {
// check if this is a rounding-to-even case.
Expand Down Expand Up @@ -147,7 +147,7 @@ fn check_exact<F, T>(mut f: F, v: T, vstr: &str, expected: &[u8], expectedk: i16
// check infinite zero digits
if let Some(cut) = cut {
for i in cut..expected.len()-1 {
expected_[..cut].clone_from_slice(&expected[..cut]);
expected_[..cut].copy_from_slice(&expected[..cut]);
for c in &mut expected_[cut..i] { *c = b'0'; }

try_exact!(f(&decoded) => &mut buf, &expected_[..i], expectedk;
Expand Down
5 changes: 3 additions & 2 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
test(attr(deny(warnings))))]
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(copy_from_slice)]
#![feature(rustc_private)]
#![feature(staged_api)]

Expand Down Expand Up @@ -519,7 +520,7 @@ pub mod reader {
// of the page and segfault.

let mut b = [0; 8];
b.clone_from_slice(&d.data[d.end - 8..d.end]);
b.copy_from_slice(&d.data[d.end - 8..d.end]);
let data = unsafe { (*(b.as_ptr() as *const u64)).to_be() };
let len = d.end - d.start;
if len < 8 {
Expand Down Expand Up @@ -1043,7 +1044,7 @@ pub mod writer {
{
let last_size_pos = last_size_pos as usize;
let data = &self.writer.get_ref()[last_size_pos + 4..cur_pos as usize];
buf[..size].clone_from_slice(data);
buf[..size].copy_from_slice(data);
}

// overwrite the size and data and continue
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![feature(cell_extras)]
#![feature(collections)]
#![feature(const_fn)]
#![feature(copy_from_slice)]
#![feature(enumset)]
#![feature(iter_arith)]
#![feature(libc)]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
let bits = &mut self.scope_kills[start.. end];
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [before]",
self.analysis_name, flow_exit, mut_bits_to_string(bits));
bits.clone_from_slice(&orig_kills[..]);
bits.copy_from_slice(&orig_kills[..]);
debug!("{} add_kills_from_flow_exits flow_exit={:?} bits={} [after]",
self.analysis_name, flow_exit, mut_bits_to_string(bits));
}
Expand Down Expand Up @@ -556,7 +556,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
let (start, end) = self.dfcx.compute_id_range(node_index);

// Initialize local bitvector with state on-entry.
in_out.clone_from_slice(&self.dfcx.on_entry[start.. end]);
in_out.copy_from_slice(&self.dfcx.on_entry[start.. end]);

// Compute state on-exit by applying transfer function to
// state on-entry.
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(box_syntax)]
#![feature(copy_from_slice)]
#![feature(libc)]
#![feature(rand)]
#![feature(rustc_private)]
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_back/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ impl FixedBuffer for FixedBuffer64 {
let buffer_remaining = size - self.buffer_idx;
if input.len() >= buffer_remaining {
self.buffer[self.buffer_idx..size]
.clone_from_slice(&input[..buffer_remaining]);
.copy_from_slice(&input[..buffer_remaining]);
self.buffer_idx = 0;
func(&self.buffer);
i += buffer_remaining;
} else {
self.buffer[self.buffer_idx..self.buffer_idx + input.len()]
.clone_from_slice(input);
.copy_from_slice(input);
self.buffer_idx += input.len();
return;
}
Expand All @@ -157,7 +157,7 @@ impl FixedBuffer for FixedBuffer64 {
// data left in the input vector will be less than the buffer size and the buffer will
// be empty.
let input_remaining = input.len() - i;
self.buffer[..input_remaining].clone_from_slice(&input[i..]);
self.buffer[..input_remaining].copy_from_slice(&input[i..]);
self.buffer_idx += input_remaining;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Write for Cursor<Vec<u8>> {
let pos = pos as usize;
let space = self.inner.len() - pos;
let (left, right) = buf.split_at(cmp::min(space, buf.len()));
self.inner[pos..pos + left.len()].clone_from_slice(left);
self.inner[pos..pos + left.len()].copy_from_slice(left);
self.inner.extend_from_slice(right);
}

Expand Down
6 changes: 3 additions & 3 deletions src/libstd/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'a> Read for &'a [u8] {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let amt = cmp::min(buf.len(), self.len());
let (a, b) = self.split_at(amt);
buf[..amt].clone_from_slice(a);
buf[..amt].copy_from_slice(a);
*self = b;
Ok(amt)
}
Expand All @@ -168,7 +168,7 @@ impl<'a> Read for &'a [u8] {
"failed to fill whole buffer"));
}
let (a, b) = self.split_at(buf.len());
buf.clone_from_slice(a);
buf.copy_from_slice(a);
*self = b;
Ok(())
}
Expand All @@ -189,7 +189,7 @@ impl<'a> Write for &'a mut [u8] {
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
let amt = cmp::min(data.len(), self.len());
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt);
a.clone_from_slice(&data[..amt]);
a.copy_from_slice(&data[..amt]);
*self = b;
Ok(amt)
}
Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
#![feature(collections)]
#![feature(collections_bound)]
#![feature(const_fn)]
#![feature(copy_from_slice)]
#![feature(core_float)]
#![feature(core_intrinsics)]
#![feature(decode_utf16)]
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl<'a> Parser<'a> {
fn ipv6_addr_from_head_tail(head: &[u16], tail: &[u16]) -> Ipv6Addr {
assert!(head.len() + tail.len() <= 8);
let mut gs = [0; 8];
gs[..head.len()].clone_from_slice(head);
gs[(8 - tail.len()) .. 8].clone_from_slice(tail);
gs[..head.len()].copy_from_slice(head);
gs[(8 - tail.len()) .. 8].copy_from_slice(tail);
Ipv6Addr::new(gs[0], gs[1], gs[2], gs[3], gs[4], gs[5], gs[6], gs[7])
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl Wtf8Buf {
Some((surrogate_pos, _)) => {
pos = surrogate_pos + 3;
self.bytes[surrogate_pos..pos]
.clone_from_slice(UTF8_REPLACEMENT_CHARACTER);
.copy_from_slice(UTF8_REPLACEMENT_CHARACTER);
},
None => return unsafe { String::from_utf8_unchecked(self.bytes) }
}
Expand Down