Skip to content

Commit dd44ea0

Browse files
Remove offset_from polyfill
1 parent c5d7955 commit dd44ea0

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

src/bytes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::buf::IntoIter;
1616
#[allow(unused)]
1717
use crate::loom::sync::atomic::AtomicMut;
1818
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
19-
use crate::{offset_from, Buf, BytesMut};
19+
use crate::{Buf, BytesMut};
2020

2121
/// A cheaply cloneable and sliceable chunk of contiguous memory.
2222
///
@@ -1235,7 +1235,7 @@ unsafe fn promotable_to_vec(
12351235

12361236
let buf = f(shared);
12371237

1238-
let cap = offset_from(ptr, buf) + len;
1238+
let cap = ptr.offset_from(buf) as usize + len;
12391239

12401240
// Copy back buffer
12411241
ptr::copy(ptr, buf, len);
@@ -1263,7 +1263,7 @@ unsafe fn promotable_to_mut(
12631263
debug_assert_eq!(kind, KIND_VEC);
12641264

12651265
let buf = f(shared);
1266-
let off = offset_from(ptr, buf);
1266+
let off = ptr.offset_from(buf) as usize;
12671267
let cap = off + len;
12681268
let v = Vec::from_raw_parts(buf, cap, cap);
12691269

@@ -1348,7 +1348,7 @@ unsafe fn promotable_is_unique(data: &AtomicPtr<()>) -> bool {
13481348
}
13491349

13501350
unsafe fn free_boxed_slice(buf: *mut u8, offset: *const u8, len: usize) {
1351-
let cap = offset_from(offset, buf) + len;
1351+
let cap = offset.offset_from(buf) as usize + len;
13521352
dealloc(buf, Layout::from_size_align(cap, 1).unwrap())
13531353
}
13541354

@@ -1444,7 +1444,7 @@ unsafe fn shared_to_mut_impl(shared: *mut Shared, ptr: *const u8, len: usize) ->
14441444
let cap = shared.cap;
14451445

14461446
// Rebuild Vec
1447-
let off = offset_from(ptr, buf);
1447+
let off = ptr.offset_from(buf) as usize;
14481448
let v = Vec::from_raw_parts(buf, len + off, cap);
14491449

14501450
let mut b = BytesMut::from_vec(v);
@@ -1510,7 +1510,7 @@ unsafe fn shallow_clone_vec(
15101510
// vector.
15111511
let shared = Box::new(Shared {
15121512
buf,
1513-
cap: offset_from(offset, buf) + len,
1513+
cap: offset.offset_from(buf) as usize + len,
15141514
// Initialize refcount to 2. One for this reference, and one
15151515
// for the new clone that will be returned from
15161516
// `shallow_clone`.

src/bytes_mut.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::bytes::Vtable;
1717
#[allow(unused)]
1818
use crate::loom::sync::atomic::AtomicMut;
1919
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
20-
use crate::{offset_from, Buf, BufMut, Bytes, TryGetError};
20+
use crate::{Buf, BufMut, Bytes, TryGetError};
2121

2222
/// A unique reference to a contiguous slice of memory.
2323
///
@@ -694,7 +694,7 @@ impl BytesMut {
694694
let v_capacity = v.capacity();
695695
let ptr = v.as_mut_ptr();
696696

697-
let offset = offset_from(self.ptr.as_ptr(), ptr);
697+
let offset = self.ptr.as_ptr().offset_from(ptr) as usize;
698698

699699
// Compare the condition in the `kind == KIND_VEC` case above
700700
// for more details.
@@ -1823,7 +1823,7 @@ unsafe fn shared_v_to_mut(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> B
18231823
let v = &mut shared.vec;
18241824
let v_capacity = v.capacity();
18251825
let v_ptr = v.as_mut_ptr();
1826-
let offset = offset_from(ptr as *mut u8, v_ptr);
1826+
let offset = ptr.offset_from(v_ptr) as usize;
18271827
let cap = v_capacity - offset;
18281828

18291829
let ptr = vptr(ptr as *mut u8);

src/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,3 @@ fn panic_does_not_fit(size: usize, nbytes: usize) -> ! {
182182
size, nbytes
183183
);
184184
}
185-
186-
/// Precondition: dst >= original
187-
///
188-
/// The following line is equivalent to:
189-
///
190-
/// ```rust,ignore
191-
/// self.ptr.as_ptr().offset_from(ptr) as usize;
192-
/// ```
193-
///
194-
/// But due to min rust is 1.39 and it is only stabilized
195-
/// in 1.47, we cannot use it.
196-
#[inline]
197-
fn offset_from(dst: *const u8, original: *const u8) -> usize {
198-
dst as usize - original as usize
199-
}

0 commit comments

Comments
 (0)