Skip to content

Commit 61b964a

Browse files
committed
Minor code clean-ups
as suggested by clippy
1 parent a2c0504 commit 61b964a

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

lib.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<A: Array> SmallVec<A> {
641641
}
642642
let (ptr, len_ptr, _) = self.triple_mut();
643643
*len_ptr = len + 1;
644-
ptr::write(ptr.offset(len as isize), value);
644+
ptr::write(ptr.add(len), value);
645645
}
646646
}
647647

@@ -655,7 +655,7 @@ impl<A: Array> SmallVec<A> {
655655
}
656656
let last_index = *len_ptr - 1;
657657
*len_ptr = last_index;
658-
Some(ptr::read(ptr.offset(last_index as isize)))
658+
Some(ptr::read(ptr.add(last_index)))
659659
}
660660
}
661661

@@ -761,7 +761,7 @@ impl<A: Array> SmallVec<A> {
761761
while len < *len_ptr {
762762
let last_index = *len_ptr - 1;
763763
*len_ptr = last_index;
764-
ptr::drop_in_place(ptr.offset(last_index as isize));
764+
ptr::drop_in_place(ptr.add(last_index));
765765
}
766766
}
767767
}
@@ -809,9 +809,9 @@ impl<A: Array> SmallVec<A> {
809809
let len = *len_ptr;
810810
assert!(index < len);
811811
*len_ptr = len - 1;
812-
ptr = ptr.offset(index as isize);
812+
ptr = ptr.add(index);
813813
let item = ptr::read(ptr);
814-
ptr::copy(ptr.offset(1), ptr, len - index - 1);
814+
ptr::copy(ptr.add(1), ptr, len - index - 1);
815815
item
816816
}
817817
}
@@ -827,8 +827,8 @@ impl<A: Array> SmallVec<A> {
827827
let len = *len_ptr;
828828
assert!(index <= len);
829829
*len_ptr = len + 1;
830-
ptr = ptr.offset(index as isize);
831-
ptr::copy(ptr, ptr.offset(1), len - index);
830+
ptr = ptr.add(index);
831+
ptr::copy(ptr, ptr.add(1), len - index);
832832
ptr::write(ptr, element);
833833
}
834834
}
@@ -849,32 +849,32 @@ impl<A: Array> SmallVec<A> {
849849
unsafe {
850850
let old_len = self.len();
851851
assert!(index <= old_len);
852-
let mut ptr = self.as_mut_ptr().offset(index as isize);
852+
let mut ptr = self.as_mut_ptr().add(index);
853853

854854
// Move the trailing elements.
855-
ptr::copy(ptr, ptr.offset(lower_size_bound as isize), old_len - index);
855+
ptr::copy(ptr, ptr.add(lower_size_bound), old_len - index);
856856

857857
// In case the iterator panics, don't double-drop the items we just copied above.
858858
self.set_len(index);
859859

860860
let mut num_added = 0;
861861
for element in iter {
862-
let mut cur = ptr.offset(num_added as isize);
862+
let mut cur = ptr.add(num_added);
863863
if num_added >= lower_size_bound {
864864
// Iterator provided more elements than the hint. Move trailing items again.
865865
self.reserve(1);
866-
ptr = self.as_mut_ptr().offset(index as isize);
867-
cur = ptr.offset(num_added as isize);
868-
ptr::copy(cur, cur.offset(1), old_len - index);
866+
ptr = self.as_mut_ptr().add(index);
867+
cur = ptr.add(num_added);
868+
ptr::copy(cur, cur.add(1), old_len - index);
869869
}
870870
ptr::write(cur, element);
871871
num_added += 1;
872872
}
873873
if num_added < lower_size_bound {
874874
// Iterator provided fewer elements than the hint
875875
ptr::copy(
876-
ptr.offset(lower_size_bound as isize),
877-
ptr.offset(num_added as isize),
876+
ptr.add(lower_size_bound),
877+
ptr.add(num_added),
878878
old_len - index,
879879
);
880880
}
@@ -957,11 +957,11 @@ impl<A: Array> SmallVec<A> {
957957

958958
unsafe {
959959
for r in 1..len {
960-
let p_r = ptr.offset(r as isize);
961-
let p_wm1 = ptr.offset((w - 1) as isize);
960+
let p_r = ptr.add(r);
961+
let p_wm1 = ptr.add(w - 1);
962962
if !same_bucket(&mut *p_r, &mut *p_wm1) {
963963
if r != w {
964-
let p_w = p_wm1.offset(1);
964+
let p_w = p_wm1.add(1);
965965
mem::swap(&mut *p_r, &mut *p_w);
966966
}
967967
w += 1;
@@ -1039,8 +1039,8 @@ impl<A: Array> SmallVec<A> {
10391039
/// // writing into the old `SmallVec`'s inline storage on the
10401040
/// // stack.
10411041
/// assert!(spilled);
1042-
/// for i in 0..len as isize {
1043-
/// ptr::write(p.offset(i), 4 + i);
1042+
/// for i in 0..len {
1043+
/// ptr::write(p.add(i), 4 + i);
10441044
/// }
10451045
///
10461046
/// // Put everything back together into a SmallVec with a different
@@ -1103,8 +1103,8 @@ where
11031103

11041104
unsafe {
11051105
let slice_ptr = slice.as_ptr();
1106-
let ptr = self.as_mut_ptr().offset(index as isize);
1107-
ptr::copy(ptr, ptr.offset(slice.len() as isize), len - index);
1106+
let ptr = self.as_mut_ptr().add(index);
1107+
ptr::copy(ptr, ptr.add(slice.len()), len - index);
11081108
ptr::copy_nonoverlapping(slice_ptr, ptr, slice.len());
11091109
self.set_len(len + slice.len());
11101110
}
@@ -1156,8 +1156,8 @@ where
11561156
let (ptr, len_ptr, _) = v.triple_mut();
11571157
let mut local_len = SetLenOnDrop::new(len_ptr);
11581158

1159-
for i in 0..n as isize {
1160-
::core::ptr::write(ptr.offset(i), elem.clone());
1159+
for i in 0..n {
1160+
::core::ptr::write(ptr.add(i), elem.clone());
11611161
local_len.increment_len(1);
11621162
}
11631163
}
@@ -1318,7 +1318,7 @@ where
13181318
#[cfg(not(feature = "specialization"))]
13191319
#[inline]
13201320
fn from(slice: &'a [A::Item]) -> SmallVec<A> {
1321-
slice.into_iter().cloned().collect()
1321+
slice.iter().cloned().collect()
13221322
}
13231323

13241324
#[cfg(feature = "specialization")]
@@ -1384,7 +1384,7 @@ impl<A: Array> Extend<A::Item> for SmallVec<A> {
13841384
let mut len = SetLenOnDrop::new(len_ptr);
13851385
while len.get() < cap {
13861386
if let Some(out) = iter.next() {
1387-
ptr::write(ptr.offset(len.get() as isize), out);
1387+
ptr::write(ptr.add(len.get()), out);
13881388
len.increment_len(1);
13891389
} else {
13901390
return;
@@ -1463,10 +1463,6 @@ where
14631463
fn eq(&self, other: &SmallVec<B>) -> bool {
14641464
self[..] == other[..]
14651465
}
1466-
#[inline]
1467-
fn ne(&self, other: &SmallVec<B>) -> bool {
1468-
self[..] != other[..]
1469-
}
14701466
}
14711467

14721468
impl<A: Array> Eq for SmallVec<A> where A::Item: Eq {}
@@ -1528,9 +1524,9 @@ impl<A: Array> Iterator for IntoIter<A> {
15281524
None
15291525
} else {
15301526
unsafe {
1531-
let current = self.current as isize;
1527+
let current = self.current;
15321528
self.current += 1;
1533-
Some(ptr::read(self.data.as_ptr().offset(current)))
1529+
Some(ptr::read(self.data.as_ptr().add(current)))
15341530
}
15351531
}
15361532
}
@@ -1550,7 +1546,7 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
15501546
} else {
15511547
unsafe {
15521548
self.end -= 1;
1553-
Some(ptr::read(self.data.as_ptr().offset(self.end as isize)))
1549+
Some(ptr::read(self.data.as_ptr().add(self.end)))
15541550
}
15551551
}
15561552
}
@@ -1613,7 +1609,7 @@ impl<'a> SetLenOnDrop<'a> {
16131609
fn new(len: &'a mut usize) -> Self {
16141610
SetLenOnDrop {
16151611
local_len: *len,
1616-
len: len,
1612+
len,
16171613
}
16181614
}
16191615

@@ -1649,7 +1645,7 @@ macro_rules! impl_array(
16491645
impl_array!(
16501646
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, 0x40, 0x60, 0x80,
16511647
0x100, 0x200, 0x400, 0x600, 0x800, 0x1000, 0x2000, 0x4000, 0x6000, 0x8000, 0x10000, 0x20000,
1652-
0x40000, 0x60000, 0x80000, 0x100000
1648+
0x40000, 0x60000, 0x80000, 0x10_0000
16531649
);
16541650

16551651
#[cfg(test)]

0 commit comments

Comments
 (0)