diff options
| author | Corey Farwell <coreyf@rwell.org> | 2018-08-19 22:16:22 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2018-08-20 07:28:34 -0400 |
| commit | 993fb934640b7e514f3c629c33a2698a83ed8c3e (patch) | |
| tree | 98cb19e128d3d8a5c32b620bebc16fae8b3877b7 /src/liballoc/collections | |
| parent | 6bf6d50a6ff7685b4aa09172d9d09f03f250da9d (diff) | |
| download | rust-993fb934640b7e514f3c629c33a2698a83ed8c3e.tar.gz rust-993fb934640b7e514f3c629c33a2698a83ed8c3e.zip | |
Replace usages of ptr::offset with ptr::{add,sub}.
Diffstat (limited to 'src/liballoc/collections')
| -rw-r--r-- | src/liballoc/collections/btree/node.rs | 48 | ||||
| -rw-r--r-- | src/liballoc/collections/vec_deque.rs | 42 |
2 files changed, 45 insertions, 45 deletions
diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 0ae45b31232..0315545262b 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -1151,12 +1151,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV> let new_len = self.node.len() - self.idx - 1; ptr::copy_nonoverlapping( - self.node.keys().as_ptr().offset(self.idx as isize + 1), + self.node.keys().as_ptr().add(self.idx + 1), new_node.keys.as_mut_ptr(), new_len ); ptr::copy_nonoverlapping( - self.node.vals().as_ptr().offset(self.idx as isize + 1), + self.node.vals().as_ptr().add(self.idx + 1), new_node.vals.as_mut_ptr(), new_len ); @@ -1209,17 +1209,17 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: let new_len = self.node.len() - self.idx - 1; ptr::copy_nonoverlapping( - self.node.keys().as_ptr().offset(self.idx as isize + 1), + self.node.keys().as_ptr().add(self.idx + 1), new_node.data.keys.as_mut_ptr(), new_len ); ptr::copy_nonoverlapping( - self.node.vals().as_ptr().offset(self.idx as isize + 1), + self.node.vals().as_ptr().add(self.idx + 1), new_node.data.vals.as_mut_ptr(), new_len ); ptr::copy_nonoverlapping( - self.node.as_internal().edges.as_ptr().offset(self.idx as isize + 1), + self.node.as_internal().edges.as_ptr().add(self.idx + 1), new_node.edges.as_mut_ptr(), new_len + 1 ); @@ -1283,14 +1283,14 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: slice_remove(self.node.keys_mut(), self.idx)); ptr::copy_nonoverlapping( right_node.keys().as_ptr(), - left_node.keys_mut().as_mut_ptr().offset(left_len as isize + 1), + left_node.keys_mut().as_mut_ptr().add(left_len + 1), right_len ); ptr::write(left_node.vals_mut().get_unchecked_mut(left_len), slice_remove(self.node.vals_mut(), self.idx)); ptr::copy_nonoverlapping( right_node.vals().as_ptr(), - left_node.vals_mut().as_mut_ptr().offset(left_len as isize + 1), + left_node.vals_mut().as_mut_ptr().add(left_len + 1), right_len ); @@ -1309,7 +1309,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: .as_internal_mut() .edges .as_mut_ptr() - .offset(left_len as isize + 1), + .add(left_len + 1), right_len + 1 ); @@ -1394,10 +1394,10 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: // Make room for stolen elements in the right child. ptr::copy(right_kv.0, - right_kv.0.offset(count as isize), + right_kv.0.add(count), right_len); ptr::copy(right_kv.1, - right_kv.1.offset(count as isize), + right_kv.1.add(count), right_len); // Move elements from the left child to the right one. @@ -1418,7 +1418,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: // Make room for stolen edges. let right_edges = right.reborrow_mut().as_internal_mut().edges.as_mut_ptr(); ptr::copy(right_edges, - right_edges.offset(count as isize), + right_edges.add(count), right_len + 1); right.correct_childrens_parent_links(count, count + right_len + 1); @@ -1463,10 +1463,10 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: move_kv(right_kv, count - 1, parent_kv, 0, 1); // Fix right indexing - ptr::copy(right_kv.0.offset(count as isize), + ptr::copy(right_kv.0.add(count), right_kv.0, new_right_len); - ptr::copy(right_kv.1.offset(count as isize), + ptr::copy(right_kv.1.add(count), right_kv.1, new_right_len); } @@ -1480,7 +1480,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: // Fix right indexing. let right_edges = right.reborrow_mut().as_internal_mut().edges.as_mut_ptr(); - ptr::copy(right_edges.offset(count as isize), + ptr::copy(right_edges.add(count), right_edges, new_right_len + 1); right.correct_childrens_parent_links(0, new_right_len + 1); @@ -1497,11 +1497,11 @@ unsafe fn move_kv<K, V>( dest: (*mut K, *mut V), dest_offset: usize, count: usize) { - ptr::copy_nonoverlapping(source.0.offset(source_offset as isize), - dest.0.offset(dest_offset as isize), + ptr::copy_nonoverlapping(source.0.add(source_offset), + dest.0.add(dest_offset), count); - ptr::copy_nonoverlapping(source.1.offset(source_offset as isize), - dest.1.offset(dest_offset as isize), + ptr::copy_nonoverlapping(source.1.add(source_offset), + dest.1.add(dest_offset), count); } @@ -1513,8 +1513,8 @@ unsafe fn move_edges<K, V>( { let source_ptr = source.as_internal_mut().edges.as_mut_ptr(); let dest_ptr = dest.as_internal_mut().edges.as_mut_ptr(); - ptr::copy_nonoverlapping(source_ptr.offset(source_offset as isize), - dest_ptr.offset(dest_offset as isize), + ptr::copy_nonoverlapping(source_ptr.add(source_offset), + dest_ptr.add(dest_offset), count); dest.correct_childrens_parent_links(dest_offset, dest_offset + count); } @@ -1604,8 +1604,8 @@ pub mod marker { unsafe fn slice_insert<T>(slice: &mut [T], idx: usize, val: T) { ptr::copy( - slice.as_ptr().offset(idx as isize), - slice.as_mut_ptr().offset(idx as isize + 1), + slice.as_ptr().add(idx), + slice.as_mut_ptr().add(idx + 1), slice.len() - idx ); ptr::write(slice.get_unchecked_mut(idx), val); @@ -1614,8 +1614,8 @@ unsafe fn slice_insert<T>(slice: &mut [T], idx: usize, val: T) { unsafe fn slice_remove<T>(slice: &mut [T], idx: usize) -> T { let ret = ptr::read(slice.get_unchecked(idx)); ptr::copy( - slice.as_ptr().offset(idx as isize + 1), - slice.as_mut_ptr().offset(idx as isize), + slice.as_ptr().add(idx + 1), + slice.as_mut_ptr().add(idx), slice.len() - idx - 1 ); ret diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 0f759bb8f0b..55c8a78f8d0 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -126,13 +126,13 @@ impl<T> VecDeque<T> { /// Moves an element out of the buffer #[inline] unsafe fn buffer_read(&mut self, off: usize) -> T { - ptr::read(self.ptr().offset(off as isize)) + ptr::read(self.ptr().add(off)) } /// Writes an element into the buffer, moving it. #[inline] unsafe fn buffer_write(&mut self, off: usize, value: T) { - ptr::write(self.ptr().offset(off as isize), value); + ptr::write(self.ptr().add(off), value); } /// Returns `true` if and only if the buffer is at full capacity. @@ -177,8 +177,8 @@ impl<T> VecDeque<T> { src, len, self.cap()); - ptr::copy(self.ptr().offset(src as isize), - self.ptr().offset(dst as isize), + ptr::copy(self.ptr().add(src), + self.ptr().add(dst), len); } @@ -197,8 +197,8 @@ impl<T> VecDeque<T> { src, len, self.cap()); - ptr::copy_nonoverlapping(self.ptr().offset(src as isize), - self.ptr().offset(dst as isize), + ptr::copy_nonoverlapping(self.ptr().add(src), + self.ptr().add(dst), len); } @@ -436,7 +436,7 @@ impl<T> VecDeque<T> { pub fn get(&self, index: usize) -> Option<&T> { if index < self.len() { let idx = self.wrap_add(self.tail, index); - unsafe { Some(&*self.ptr().offset(idx as isize)) } + unsafe { Some(&*self.ptr().add(idx)) } } else { None } @@ -465,7 +465,7 @@ impl<T> VecDeque<T> { pub fn get_mut(&mut self, index: usize) -> Option<&mut T> { if index < self.len() { let idx = self.wrap_add(self.tail, index); - unsafe { Some(&mut *self.ptr().offset(idx as isize)) } + unsafe { Some(&mut *self.ptr().add(idx)) } } else { None } @@ -501,8 +501,8 @@ impl<T> VecDeque<T> { let ri = self.wrap_add(self.tail, i); let rj = self.wrap_add(self.tail, j); unsafe { - ptr::swap(self.ptr().offset(ri as isize), - self.ptr().offset(rj as isize)) + ptr::swap(self.ptr().add(ri), + self.ptr().add(rj)) } } @@ -1805,20 +1805,20 @@ impl<T> VecDeque<T> { // `at` lies in the first half. let amount_in_first = first_len - at; - ptr::copy_nonoverlapping(first_half.as_ptr().offset(at as isize), + ptr::copy_nonoverlapping(first_half.as_ptr().add(at), other.ptr(), amount_in_first); // just take all of the second half. ptr::copy_nonoverlapping(second_half.as_ptr(), - other.ptr().offset(amount_in_first as isize), + other.ptr().add(amount_in_first), 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(second_half.as_ptr().offset(offset as isize), + ptr::copy_nonoverlapping(second_half.as_ptr().add(offset), other.ptr(), amount_in_second); } @@ -2709,24 +2709,24 @@ impl<T> From<VecDeque<T>> for Vec<T> { // Need to move the ring to the front of the buffer, as vec will expect this. if other.is_contiguous() { - ptr::copy(buf.offset(tail as isize), buf, len); + ptr::copy(buf.add(tail), buf, len); } else { if (tail - head) >= cmp::min(cap - tail, head) { // There is enough free space in the centre for the shortest block so we can // do this in at most three copy moves. if (cap - tail) > head { // right hand block is the long one; move that enough for the left - ptr::copy(buf.offset(tail as isize), - buf.offset((tail - head) as isize), + ptr::copy(buf.add(tail), + buf.add(tail - head), cap - tail); // copy left in the end - ptr::copy(buf, buf.offset((cap - head) as isize), head); + ptr::copy(buf, buf.add(cap - head), head); // shift the new thing to the start - ptr::copy(buf.offset((tail - head) as isize), buf, len); + ptr::copy(buf.add(tail - head), buf, len); } else { // left hand block is the long one, we can do it in two! - ptr::copy(buf, buf.offset((cap - tail) as isize), head); - ptr::copy(buf.offset(tail as isize), buf, cap - tail); + ptr::copy(buf, buf.add(cap - tail), head); + ptr::copy(buf.add(tail), buf, cap - tail); } } else { // Need to use N swaps to move the ring @@ -2751,7 +2751,7 @@ impl<T> From<VecDeque<T>> for Vec<T> { for i in left_edge..right_edge { right_offset = (i - left_edge) % (cap - right_edge); let src: isize = (right_edge + right_offset) as isize; - ptr::swap(buf.offset(i as isize), buf.offset(src)); + ptr::swap(buf.add(i), buf.offset(src)); } let n_ops = right_edge - left_edge; left_edge += n_ops; |
