std: Standardize (input, output) param orderings
This functions swaps the order of arguments to a few functions that previously took (output, input) parameters, but now take (input, output) parameters (in that order). The affected functions are: * ptr::copy * ptr::copy_nonoverlapping * slice::bytes::copy_memory * intrinsics::copy * intrinsics::copy_nonoverlapping Closes #22890 [breaking-change]
This commit is contained in:
@@ -316,8 +316,8 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
|
||||
|
||||
impl<'a> fmt::Write for Filler<'a> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
slice::bytes::copy_memory(&mut self.buf[(*self.end)..],
|
||||
s.as_bytes());
|
||||
slice::bytes::copy_memory(s.as_bytes(),
|
||||
&mut self.buf[(*self.end)..]);
|
||||
*self.end += s.len();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -293,9 +293,9 @@ extern "rust-intrinsic" {
|
||||
/// let mut t: T = mem::uninitialized();
|
||||
///
|
||||
/// // Perform the swap, `&mut` pointers never alias
|
||||
/// ptr::copy_nonoverlapping(&mut t, &*x, 1);
|
||||
/// ptr::copy_nonoverlapping(x, &*y, 1);
|
||||
/// ptr::copy_nonoverlapping(y, &t, 1);
|
||||
/// ptr::copy_nonoverlapping(x, &mut t, 1);
|
||||
/// ptr::copy_nonoverlapping(y, x, 1);
|
||||
/// ptr::copy_nonoverlapping(&t, y, 1);
|
||||
///
|
||||
/// // y and t now point to the same thing, but we need to completely forget `tmp`
|
||||
/// // because it's no longer relevant.
|
||||
@@ -304,6 +304,12 @@ extern "rust-intrinsic" {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(not(stage0))]
|
||||
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
|
||||
|
||||
/// dox
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(stage0)]
|
||||
pub fn copy_nonoverlapping<T>(dst: *mut T, src: *const T, count: usize);
|
||||
|
||||
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
|
||||
@@ -329,12 +335,18 @@ extern "rust-intrinsic" {
|
||||
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
|
||||
/// let mut dst = Vec::with_capacity(elts);
|
||||
/// dst.set_len(elts);
|
||||
/// ptr::copy(dst.as_mut_ptr(), ptr, elts);
|
||||
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
|
||||
/// dst
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(not(stage0))]
|
||||
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
||||
|
||||
/// dox
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(stage0)]
|
||||
pub fn copy<T>(dst: *mut T, src: *const T, count: usize);
|
||||
|
||||
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
|
||||
|
||||
@@ -229,9 +229,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||
let mut t: T = uninitialized();
|
||||
|
||||
// Perform the swap, `&mut` pointers never alias
|
||||
ptr::copy_nonoverlapping(&mut t, &*x, 1);
|
||||
ptr::copy_nonoverlapping(x, &*y, 1);
|
||||
ptr::copy_nonoverlapping(y, &t, 1);
|
||||
ptr::copy_nonoverlapping(&*x, &mut t, 1);
|
||||
ptr::copy_nonoverlapping(&*y, x, 1);
|
||||
ptr::copy_nonoverlapping(&t, y, 1);
|
||||
|
||||
// y and t now point to the same thing, but we need to completely forget `t`
|
||||
// because it's no longer relevant.
|
||||
|
||||
@@ -104,11 +104,28 @@ use cmp::Ordering::{self, Less, Equal, Greater};
|
||||
// FIXME #19649: intrinsic docs don't render, so these have no docs :(
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(not(stage0))]
|
||||
pub use intrinsics::copy_nonoverlapping;
|
||||
|
||||
/// dox
|
||||
#[cfg(stage0)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
|
||||
intrinsics::copy_nonoverlapping(dst, src, count)
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg(not(stage0))]
|
||||
pub use intrinsics::copy;
|
||||
|
||||
/// dox
|
||||
#[cfg(stage0)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
|
||||
intrinsics::copy(dst, src, count)
|
||||
}
|
||||
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use intrinsics::write_bytes;
|
||||
|
||||
@@ -167,12 +184,11 @@ pub unsafe fn zero_memory<T>(dst: *mut T, count: usize) {
|
||||
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
|
||||
// Give ourselves some scratch space to work with
|
||||
let mut tmp: T = mem::uninitialized();
|
||||
let t: *mut T = &mut tmp;
|
||||
|
||||
// Perform the swap
|
||||
copy_nonoverlapping(t, &*x, 1);
|
||||
copy(x, &*y, 1); // `x` and `y` may overlap
|
||||
copy_nonoverlapping(y, &*t, 1);
|
||||
copy_nonoverlapping(x, &mut tmp, 1);
|
||||
copy(y, x, 1); // `x` and `y` may overlap
|
||||
copy_nonoverlapping(&tmp, y, 1);
|
||||
|
||||
// y and t now point to the same thing, but we need to completely forget `tmp`
|
||||
// because it's no longer relevant.
|
||||
@@ -208,7 +224,7 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn read<T>(src: *const T) -> T {
|
||||
let mut tmp: T = mem::uninitialized();
|
||||
copy_nonoverlapping(&mut tmp, src, 1);
|
||||
copy_nonoverlapping(src, &mut tmp, 1);
|
||||
tmp
|
||||
}
|
||||
|
||||
|
||||
@@ -1577,14 +1577,14 @@ pub mod bytes {
|
||||
///
|
||||
/// Panics if the length of `dst` is less than the length of `src`.
|
||||
#[inline]
|
||||
pub fn copy_memory(dst: &mut [u8], src: &[u8]) {
|
||||
pub fn copy_memory(src: &[u8], dst: &mut [u8]) {
|
||||
let len_src = src.len();
|
||||
assert!(dst.len() >= len_src);
|
||||
// `dst` is unaliasable, so we know statically it doesn't overlap
|
||||
// with `src`.
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(dst.as_mut_ptr(),
|
||||
src.as_ptr(),
|
||||
ptr::copy_nonoverlapping(src.as_ptr(),
|
||||
dst.as_mut_ptr(),
|
||||
len_src);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user