diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-27 11:12:28 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-30 14:08:40 -0700 |
| commit | acd48a2b3e7fcc0372f7718a2fac1cf80e03db95 (patch) | |
| tree | bf57c82936ee2c1e1df23edd0a750ec6aa75021d /src/libcore | |
| parent | 14192d6df5cc714e5c9a3ca70b08f2514d977be2 (diff) | |
| download | rust-acd48a2b3e7fcc0372f7718a2fac1cf80e03db95.tar.gz rust-acd48a2b3e7fcc0372f7718a2fac1cf80e03db95.zip | |
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]
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/fmt/float.rs | 4 | ||||
| -rw-r--r-- | src/libcore/intrinsics.rs | 20 | ||||
| -rw-r--r-- | src/libcore/mem.rs | 6 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 26 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 6 |
5 files changed, 45 insertions, 17 deletions
diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 6e82b18abc6..6a5943265ca 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -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(()) } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 1b3c83ecf15..43cf64bf3ad 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -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>()` diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 434a5d17a92..98e8668239b 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -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. diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 07d018dea92..41a70ef708f 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -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 } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 12cfdbf5306..223a0bdae36 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -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); } } |
