-
Notifications
You must be signed in to change notification settings - Fork 147
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
New modifications #155
Closed
Closed
New modifications #155
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9534a6b
Modifies lib.rs and Cargo.toml
c410-f3r 0b90d21
Removes the VecLike struct
c410-f3r 8de1d3b
New scripts for testing
c410-f3r 93f9909
Updates the Travis.yml file
c410-f3r 4e70e25
Modifies the Array trait
c410-f3r c109e5c
Do not use the no_std feature
c410-f3r 7f73f8a
Make use of NonNull
c410-f3r e1bb097
Make use of MaybeUninit
c410-f3r d3a6c9c
Rustfmt
c410-f3r ef7c328
Splits the lib.rs file
c410-f3r 85440ce
Make use of core::hint::unreachable_unchecked
c410-f3r 94b2383
Adds the const_generics feature
c410-f3r 2063374
Adjust documentation
c410-f3r 557c4c7
Clippy
c410-f3r 950e3e3
Return a pointer in `inline` and `inline_mut`
c410-f3r d7b2352
Enable 1.36 on Travis
c410-f3r 90dcc25
Re-enable no_std
c410-f3r cd02cd3
Enable all-features on docs.rs
c410-f3r 4cc4d37
Fix some constant generics errors
c410-f3r 4b2e32c
Fix modified tests there were using String
c410-f3r 7aea556
Do not use const_generics feature on docs.rs
c410-f3r 7538698
Make constant generics work
c410-f3r 9fed114
Macro hygiene for constant generics has been fixed
c410-f3r a61da16
Allow failures in nightly
c410-f3r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ use core::{ | |
fmt, | ||
hash::{Hash, Hasher}, | ||
iter::{IntoIterator, FromIterator, repeat}, | ||
mem::{ManuallyDrop, self}, | ||
mem::{MaybeUninit, self}, | ||
ops, | ||
ptr::{self, NonNull}, | ||
slice, | ||
|
@@ -213,26 +213,26 @@ impl<'a, T: 'a> Drop for Drain<'a,T> { | |
|
||
#[cfg(feature = "union")] | ||
union SmallVecData<A: Array> { | ||
inline: ManuallyDrop<A>, | ||
inline: MaybeUninit<A>, | ||
heap: (NonNull<A::Item>, usize), | ||
} | ||
|
||
#[cfg(feature = "union")] | ||
impl<A: Array> SmallVecData<A> { | ||
#[inline] | ||
unsafe fn inline(&self) -> &A { | ||
&self.inline | ||
&*self.inline.as_ptr() | ||
} | ||
#[inline] | ||
unsafe fn inline_mut(&mut self) -> &mut A { | ||
&mut self.inline | ||
&mut *self.inline.as_mut_ptr() | ||
} | ||
#[inline] | ||
fn from_inline(inline: A) -> SmallVecData<A> { | ||
SmallVecData { inline: ManuallyDrop::new(inline) } | ||
fn from_inline(inline: MaybeUninit<A>) -> SmallVecData<A> { | ||
SmallVecData { inline } | ||
} | ||
#[inline] | ||
unsafe fn into_inline(self) -> A { ManuallyDrop::into_inner(self.inline) } | ||
unsafe fn into_inline(self) -> A { self.inline.assume_init() } | ||
#[inline] | ||
unsafe fn heap(&self) -> (*mut A::Item, usize) { | ||
(self.heap.0.as_ptr(), self.heap.1) | ||
|
@@ -249,7 +249,7 @@ impl<A: Array> SmallVecData<A> { | |
|
||
#[cfg(not(feature = "union"))] | ||
enum SmallVecData<A: Array> { | ||
Inline(ManuallyDrop<A>), | ||
Inline(MaybeUninit<A>), | ||
Heap((NonNull<A::Item>, usize)), | ||
} | ||
|
||
|
@@ -258,25 +258,25 @@ impl<A: Array> SmallVecData<A> { | |
#[inline] | ||
unsafe fn inline(&self) -> &A { | ||
match *self { | ||
SmallVecData::Inline(ref a) => a, | ||
SmallVecData::Inline(ref a) => &*a.as_ptr(), | ||
_ => debug_unreachable!(), | ||
} | ||
} | ||
#[inline] | ||
unsafe fn inline_mut(&mut self) -> &mut A { | ||
match *self { | ||
SmallVecData::Inline(ref mut a) => a, | ||
SmallVecData::Inline(ref mut a) => &mut *a.as_mut_ptr(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like |
||
_ => debug_unreachable!(), | ||
} | ||
} | ||
#[inline] | ||
fn from_inline(inline: A) -> SmallVecData<A> { | ||
SmallVecData::Inline(ManuallyDrop::new(inline)) | ||
fn from_inline(inline: MaybeUninit<A>) -> SmallVecData<A> { | ||
SmallVecData::Inline(inline) | ||
} | ||
#[inline] | ||
unsafe fn into_inline(self) -> A { | ||
match self { | ||
SmallVecData::Inline(a) => ManuallyDrop::into_inner(a), | ||
SmallVecData::Inline(a) => a.assume_init(), | ||
_ => debug_unreachable!(), | ||
} | ||
} | ||
|
@@ -421,7 +421,7 @@ impl<A: Array> SmallVec<A> { | |
pub fn from_buf(buf: A) -> SmallVec<A> { | ||
SmallVec { | ||
capacity: A::size(), | ||
data: SmallVecData::from_inline(buf), | ||
data: SmallVecData::from_inline(MaybeUninit::new(buf)), | ||
} | ||
} | ||
|
||
|
@@ -461,7 +461,7 @@ impl<A: Array> SmallVec<A> { | |
pub unsafe fn from_buf_and_len_unchecked(buf: A, len: usize) -> SmallVec<A> { | ||
SmallVec { | ||
capacity: len, | ||
data: SmallVecData::from_inline(buf), | ||
data: SmallVecData::from_inline(MaybeUninit::new(buf)), | ||
} | ||
} | ||
|
||
|
@@ -979,8 +979,9 @@ impl<A: Array> SmallVec<A> where A::Item: Copy { | |
SmallVec { | ||
capacity: len, | ||
data: SmallVecData::from_inline(unsafe { | ||
let mut data: A = mem::uninitialized(); | ||
ptr::copy_nonoverlapping(slice.as_ptr(), data.as_mut_ptr(), len); | ||
let mut data = MaybeUninit::<A>::uninit(); | ||
let slice_mut = &mut *data.as_mut_ptr(); | ||
ptr::copy_nonoverlapping(slice.as_ptr(), slice_mut.as_mut_ptr(), len); | ||
data | ||
}) | ||
} | ||
|
@@ -994,7 +995,6 @@ impl<A: Array> SmallVec<A> where A::Item: Copy { | |
} | ||
} | ||
} | ||
|
||
/// Copy elements from a slice into the vector at position `index`, shifting any following | ||
/// elements toward the back. | ||
/// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's unsound to return an
&A
that points to a possibly-uninitializedA
. This method should be changed to return a raw pointer. (The callers of this method only need raw pointers anyways.)