Skip to content

Commit

Permalink
Bug fix for older Rustc versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Huszagh committed Sep 5, 2019
1 parent 5006109 commit d0382d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT/Apache-2.0"
name = "stackvector"
readme = "README.md"
repository = "https://github.com/Alexhuszagh/rust-stackvector"
version = "1.0.7"
version = "1.0.8"
build = "build.rs"

[badges]
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,30 +554,30 @@ impl<A: Array> StackVec<A> {
unsafe {
let old_len = self.len();
assert!(index <= old_len);
let mut ptr = self.as_mut_ptr().add(index);
let mut ptr = self.as_mut_ptr().padd(index);

// Move the trailing elements.
ptr::copy(ptr, ptr.add(lower_size_bound), old_len - index);
ptr::copy(ptr, ptr.padd(lower_size_bound), old_len - index);

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

let mut num_added = 0;
for element in iter {
let mut cur = ptr.add(num_added);
let mut cur = ptr.padd(num_added);
if num_added >= lower_size_bound {
// Iterator provided more elements than the hint. Move trailing items again.
assert!(self.len() + 1 <= self.capacity());
ptr = self.as_mut_ptr().add(index);
cur = ptr.add(num_added);
ptr::copy(cur, cur.add(1), old_len - index);
ptr = self.as_mut_ptr().padd(index);
cur = ptr.padd(num_added);
ptr::copy(cur, cur.padd(1), old_len - index);
}
ptr::write(cur, element);
num_added += 1;
}
if num_added < lower_size_bound {
// Iterator provided fewer elements than the hint
ptr::copy(ptr.add(lower_size_bound), ptr.add(num_added), old_len - index);
ptr::copy(ptr.padd(lower_size_bound), ptr.padd(num_added), old_len - index);
}

self.set_len(old_len + num_added);
Expand Down

0 comments on commit d0382d5

Please sign in to comment.