FIX: Remove use of uninitialized in ArrayString
We can't fix this properly (MaybeUninit with a union) until we change the user visible API (we need to require that A: Copy. As a temporary solution for arrayvec version 0.4.*, we use zeroed to initialize an array of bytes, instead of using uninitialized. This may have a negative performance impact, but the fix is to upgrade to future arrayvec 0.5.
This commit is contained in:
+3
-1
@@ -26,6 +26,7 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
/// if needed.
|
||||
#[derive(Copy)]
|
||||
pub struct ArrayString<A: Array<Item=u8>> {
|
||||
// FIXME: Use Copyable union for xs when we can
|
||||
xs: A,
|
||||
len: A::Index,
|
||||
}
|
||||
@@ -53,7 +54,8 @@ impl<A: Array<Item=u8>> ArrayString<A> {
|
||||
pub fn new() -> ArrayString<A> {
|
||||
unsafe {
|
||||
ArrayString {
|
||||
xs: ::new_array(),
|
||||
// FIXME: Use Copyable union for xs when we can
|
||||
xs: mem::zeroed(),
|
||||
len: Index::from(0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +74,6 @@ pub use array_string::ArrayString;
|
||||
pub use errors::CapacityError;
|
||||
|
||||
|
||||
unsafe fn new_array<A: Array>() -> A {
|
||||
// Note: Returning an uninitialized value here only works
|
||||
// if we can be sure the data is never used. The nullable pointer
|
||||
// inside enum optimization conflicts with this this for example,
|
||||
// so we need to be extra careful. See `NoDrop` enum.
|
||||
mem::uninitialized()
|
||||
}
|
||||
|
||||
/// A vector with a fixed capacity.
|
||||
///
|
||||
/// The `ArrayVec` is a vector backed by a fixed size array. It keeps track of
|
||||
|
||||
Reference in New Issue
Block a user