Skip to content

Commit

Permalink
remove a bit more hackery
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Dec 19, 2019
1 parent 17aa0cb commit 3ec3fca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Expand Up @@ -85,6 +85,7 @@
#![feature(const_generic_impls_guard)]
#![feature(const_generics)]
#![feature(const_in_array_repeat_expressions)]
#![cfg_attr(not(bootstrap), feature(const_if_match))]
#![feature(cow_is_borrowed)]
#![feature(dispatch_from_dyn)]
#![feature(core_intrinsics)]
Expand Down
49 changes: 8 additions & 41 deletions src/liballoc/raw_vec.rs
@@ -1,8 +1,6 @@
#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "0")]
#![doc(hidden)]

#![feature(const_if_match)]

use core::cmp;
use core::mem;
use core::ops::Drop;
Expand Down Expand Up @@ -53,9 +51,14 @@ pub struct RawVec<T, A: Alloc = Global> {
impl<T, A: Alloc> RawVec<T, A> {
/// Like `new`, but parameterized over the choice of allocator for
/// the returned `RawVec`.
#[cfg(not(bootstrap))]
pub const fn new_in(a: A) -> Self {
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
let cap = {
#[cfg(not(bootstrap))]
{ if mem::size_of::<T>() == 0 { !0 } else { 0 } }

#[cfg(bootstrap)]
[0, !0][(mem::size_of::<T>() == 0) as usize]
};

// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
RawVec {
Expand All @@ -65,17 +68,6 @@ impl<T, A: Alloc> RawVec<T, A> {
}
}

/// Like `new`, but parameterized over the choice of allocator for
/// the returned `RawVec`.
#[cfg(bootstrap)]
pub const fn new_in(a: A) -> Self {
RawVec {
ptr: Unique::empty(),
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
a,
}
}

/// Like `with_capacity`, but parameterized over the choice of
/// allocator for the returned `RawVec`.
#[inline]
Expand Down Expand Up @@ -142,33 +134,8 @@ impl<T> RawVec<T, Global> {
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
/// delayed allocation.
#[cfg(not(bootstrap))]
pub const fn new() -> Self {
// FIXME(Centril): Reintegrate this with `fn new_in` when we can.

let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };

// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
RawVec {
ptr: Unique::empty(),
cap,
a: Global,
}
}

/// Creates the biggest possible `RawVec` (on the system heap)
/// without allocating. If `T` has positive size, then this makes a
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
/// delayed allocation.
#[cfg(bootstrap)]
pub const fn new() -> Self {
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
RawVec {
ptr: Unique::empty(),
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
a: Global,
}
Self::new_in(Global)
}

/// Creates a `RawVec` (on the system heap) with exactly the
Expand Down

0 comments on commit 3ec3fca

Please sign in to comment.