Skip to content
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

std: Stabilize some ptr functions #22729

Merged
merged 1 commit into from
Feb 25, 2015
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
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#![feature(unboxed_closures)]
#![feature(unsafe_no_drop_flag)]
#![feature(core)]
#![feature(unique)]
#![cfg_attr(test, feature(test, alloc, rustc_private))]
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
feature(libc))]
Expand Down
24 changes: 12 additions & 12 deletions src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,12 +1136,12 @@ impl<K, V> Node<K, V> {
// This must be followed by insert_edge on an internal node.
#[inline]
unsafe fn insert_kv(&mut self, index: usize, key: K, val: V) -> &mut V {
ptr::copy_memory(
ptr::copy(
self.keys_mut().as_mut_ptr().offset(index as isize + 1),
self.keys().as_ptr().offset(index as isize),
self.len() - index
);
ptr::copy_memory(
ptr::copy(
self.vals_mut().as_mut_ptr().offset(index as isize + 1),
self.vals().as_ptr().offset(index as isize),
self.len() - index
Expand All @@ -1158,7 +1158,7 @@ impl<K, V> Node<K, V> {
// This can only be called immediately after a call to insert_kv.
#[inline]
unsafe fn insert_edge(&mut self, index: usize, edge: Node<K, V>) {
ptr::copy_memory(
ptr::copy(
self.edges_mut().as_mut_ptr().offset(index as isize + 1),
self.edges().as_ptr().offset(index as isize),
self.len() - index
Expand Down Expand Up @@ -1191,12 +1191,12 @@ impl<K, V> Node<K, V> {
let key = ptr::read(self.keys().get_unchecked(index));
let val = ptr::read(self.vals().get_unchecked(index));

ptr::copy_memory(
ptr::copy(
self.keys_mut().as_mut_ptr().offset(index as isize),
self.keys().as_ptr().offset(index as isize + 1),
self.len() - index - 1
);
ptr::copy_memory(
ptr::copy(
self.vals_mut().as_mut_ptr().offset(index as isize),
self.vals().as_ptr().offset(index as isize + 1),
self.len() - index - 1
Expand All @@ -1212,7 +1212,7 @@ impl<K, V> Node<K, V> {
unsafe fn remove_edge(&mut self, index: usize) -> Node<K, V> {
let edge = ptr::read(self.edges().get_unchecked(index));

ptr::copy_memory(
ptr::copy(
self.edges_mut().as_mut_ptr().offset(index as isize),
self.edges().as_ptr().offset(index as isize + 1),
self.len() - index + 1
Expand All @@ -1239,18 +1239,18 @@ impl<K, V> Node<K, V> {
unsafe {
right._len = self.len() / 2;
let right_offset = self.len() - right.len();
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
right.keys_mut().as_mut_ptr(),
self.keys().as_ptr().offset(right_offset as isize),
right.len()
);
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
right.vals_mut().as_mut_ptr(),
self.vals().as_ptr().offset(right_offset as isize),
right.len()
);
if !self.is_leaf() {
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
right.edges_mut().as_mut_ptr(),
self.edges().as_ptr().offset(right_offset as isize),
right.len() + 1
Expand Down Expand Up @@ -1280,18 +1280,18 @@ impl<K, V> Node<K, V> {
ptr::write(self.keys_mut().get_unchecked_mut(old_len), key);
ptr::write(self.vals_mut().get_unchecked_mut(old_len), val);

ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
self.keys_mut().as_mut_ptr().offset(old_len as isize + 1),
right.keys().as_ptr(),
right.len()
);
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
self.vals_mut().as_mut_ptr().offset(old_len as isize + 1),
right.vals().as_ptr(),
right.len()
);
if !self.is_leaf() {
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
self.edges_mut().as_mut_ptr().offset(old_len as isize + 1),
right.edges().as_ptr(),
right.len() + 1
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(unsafe_destructor)]
#![feature(unique)]
#![feature(unsafe_no_drop_flag)]
#![cfg_attr(test, feature(rand, rustc_private, test))]
#![cfg_attr(test, allow(deprecated))] // rand
Expand Down
26 changes: 12 additions & 14 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,10 @@ fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> O

if i != j {
let tmp = ptr::read(read_ptr);
ptr::copy_memory(buf_v.offset(j + 1),
&*buf_v.offset(j),
(i - j) as usize);
ptr::copy_nonoverlapping_memory(buf_v.offset(j),
&tmp,
1);
ptr::copy(buf_v.offset(j + 1),
&*buf_v.offset(j),
(i - j) as usize);
ptr::copy_nonoverlapping(buf_v.offset(j), &tmp, 1);
mem::forget(tmp);
}
}
Expand Down Expand Up @@ -1409,10 +1407,10 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
// j + 1 could be `len` (for the last `i`), but in
// that case, `i == j` so we don't copy. The
// `.offset(j)` is always in bounds.
ptr::copy_memory(buf_dat.offset(j + 1),
&*buf_dat.offset(j),
i - j as usize);
ptr::copy_nonoverlapping_memory(buf_dat.offset(j), read_ptr, 1);
ptr::copy(buf_dat.offset(j + 1),
&*buf_dat.offset(j),
i - j as usize);
ptr::copy_nonoverlapping(buf_dat.offset(j), read_ptr, 1);
}
}
}
Expand Down Expand Up @@ -1460,11 +1458,11 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
if left == right_start {
// the number remaining in this run.
let elems = (right_end as usize - right as usize) / mem::size_of::<T>();
ptr::copy_nonoverlapping_memory(out, &*right, elems);
ptr::copy_nonoverlapping(out, &*right, elems);
break;
} else if right == right_end {
let elems = (right_start as usize - left as usize) / mem::size_of::<T>();
ptr::copy_nonoverlapping_memory(out, &*left, elems);
ptr::copy_nonoverlapping(out, &*left, elems);
break;
}

Expand All @@ -1478,7 +1476,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
} else {
step(&mut left)
};
ptr::copy_nonoverlapping_memory(out, &*to_copy, 1);
ptr::copy_nonoverlapping(out, &*to_copy, 1);
step(&mut out);
}
}
Expand All @@ -1492,7 +1490,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
// write the result to `v` in one go, so that there are never two copies
// of the same object in `v`.
unsafe {
ptr::copy_nonoverlapping_memory(v.as_mut_ptr(), &*buf_dat, len);
ptr::copy_nonoverlapping(v.as_mut_ptr(), &*buf_dat, len);
}

// increment the pointer, returning the old pointer.
Expand Down
18 changes: 9 additions & 9 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,9 @@ impl String {

let CharRange { ch, next } = self.char_range_at(idx);
unsafe {
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as isize),
self.vec.as_ptr().offset(next as isize),
len - next);
ptr::copy(self.vec.as_mut_ptr().offset(idx as isize),
self.vec.as_ptr().offset(next as isize),
len - next);
self.vec.set_len(len - (next - idx));
}
ch
Expand Down Expand Up @@ -598,12 +598,12 @@ impl String {
let amt = ch.encode_utf8(&mut bits).unwrap();

unsafe {
ptr::copy_memory(self.vec.as_mut_ptr().offset((idx + amt) as isize),
self.vec.as_ptr().offset(idx as isize),
len - idx);
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as isize),
bits.as_ptr(),
amt);
ptr::copy(self.vec.as_mut_ptr().offset((idx + amt) as isize),
self.vec.as_ptr().offset(idx as isize),
len - idx);
ptr::copy(self.vec.as_mut_ptr().offset(idx as isize),
bits.as_ptr(),
amt);
self.vec.set_len(len + amt);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<T> Vec<T> {
pub unsafe fn from_raw_buf(ptr: *const T, elts: usize) -> Vec<T> {
let mut dst = Vec::with_capacity(elts);
dst.set_len(elts);
ptr::copy_nonoverlapping_memory(dst.as_mut_ptr(), ptr, elts);
ptr::copy_nonoverlapping(dst.as_mut_ptr(), ptr, elts);
dst
}

Expand Down Expand Up @@ -548,7 +548,7 @@ impl<T> Vec<T> {
let p = self.as_mut_ptr().offset(index as isize);
// Shift everything over to make space. (Duplicating the
// `index`th element into two consecutive places.)
ptr::copy_memory(p.offset(1), &*p, len - index);
ptr::copy(p.offset(1), &*p, len - index);
// Write it in, overwriting the first copy of the `index`th
// element.
ptr::write(&mut *p, element);
Expand Down Expand Up @@ -585,7 +585,7 @@ impl<T> Vec<T> {
ret = ptr::read(ptr);

// Shift everything down to fill in that spot.
ptr::copy_memory(ptr, &*ptr.offset(1), len - index - 1);
ptr::copy(ptr, &*ptr.offset(1), len - index - 1);
}
self.set_len(len - 1);
ret
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<T> Vec<T> {
self.reserve(other.len());
let len = self.len();
unsafe {
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
self.get_unchecked_mut(len),
other.as_ptr(),
other.len());
Expand Down Expand Up @@ -1036,7 +1036,7 @@ impl<T> Vec<T> {
self.set_len(at);
other.set_len(other_len);

ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
other.as_mut_ptr(),
self.as_ptr().offset(at as isize),
other.len());
Expand Down
22 changes: 11 additions & 11 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T> VecDeque<T> {
self.cap);
debug_assert!(src + len <= self.cap, "dst={} src={} len={} cap={}", dst, src, len,
self.cap);
ptr::copy_memory(
ptr::copy(
self.ptr.offset(dst as isize),
self.ptr.offset(src as isize),
len);
Expand All @@ -147,7 +147,7 @@ impl<T> VecDeque<T> {
self.cap);
debug_assert!(src + len <= self.cap, "dst={} src={} len={} cap={}", dst, src, len,
self.cap);
ptr::copy_nonoverlapping_memory(
ptr::copy_nonoverlapping(
self.ptr.offset(dst as isize),
self.ptr.offset(src as isize),
len);
Expand Down Expand Up @@ -1343,22 +1343,22 @@ impl<T> VecDeque<T> {
// `at` lies in the first half.
let amount_in_first = first_len - at;

ptr::copy_nonoverlapping_memory(*other.ptr,
first_half.as_ptr().offset(at as isize),
amount_in_first);
ptr::copy_nonoverlapping(*other.ptr,
first_half.as_ptr().offset(at as isize),
amount_in_first);

// just take all of the second half.
ptr::copy_nonoverlapping_memory(other.ptr.offset(amount_in_first as isize),
second_half.as_ptr(),
second_len);
ptr::copy_nonoverlapping(other.ptr.offset(amount_in_first as isize),
second_half.as_ptr(),
second_len);
} else {
// `at` lies in the second half, need to factor in the elements we skipped
// in the first half.
let offset = at - first_len;
let amount_in_second = second_len - offset;
ptr::copy_nonoverlapping_memory(*other.ptr,
second_half.as_ptr().offset(offset as isize),
amount_in_second);
ptr::copy_nonoverlapping(*other.ptr,
second_half.as_ptr().offset(offset as isize),
amount_in_second);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ extern "rust-intrinsic" {
/// }
/// }
/// ```
#[unstable(feature = "core")]
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to rename these as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt that intrinsics::copy_memory was more telling than intrinsics::copy, but laziness also kicked in as a desire to not deal with #[cfg(stage0)]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, the global namespace makes that clarification worthwhile. Carry on!

pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);

/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
Expand Down Expand Up @@ -323,13 +323,12 @@ extern "rust-intrinsic" {
/// }
/// ```
///
#[unstable(feature = "core")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);

/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
/// bytes of memory starting at `dst` to `c`.
#[unstable(feature = "core",
reason = "uncertain about naming and semantics")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);

/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,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_memory(&mut t, &*x, 1);
ptr::copy_nonoverlapping_memory(x, &*y, 1);
ptr::copy_nonoverlapping_memory(y, &t, 1);
ptr::copy_nonoverlapping(&mut t, &*x, 1);
ptr::copy_nonoverlapping(x, &*y, 1);
ptr::copy_nonoverlapping(y, &t, 1);

// y and t now point to the same thing, but we need to completely forget `t`
// because it's no longer relevant.
Expand Down
Loading