Skip to content

Commit 023bdd1

Browse files
Adding COOP_PREFERRED to Cow, ToOwned..
1 parent f5d5b8a commit 023bdd1

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

library/alloc/src/boxed.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,11 @@ where
780780
#[allow(unused_braces)]
781781
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A>
782782
where
783-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(SHORT_TERM_VEC_PREFERS_COOP!())]:,
783+
// false = no need for co-alloc metadata, since it would get lost once converted to Box.
784+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
784785
{
785786
unsafe {
786-
RawVec::<T, A, { SHORT_TERM_VEC_PREFERS_COOP!() }>::with_capacity_in(len, alloc)
787+
RawVec::<T, A, false>::with_capacity_in(len, alloc)
787788
.into_box(len)
788789
}
789790
}
@@ -815,10 +816,11 @@ where
815816
#[allow(unused_braces)]
816817
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A>
817818
where
818-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(SHORT_TERM_VEC_PREFERS_COOP!())]:,
819+
// false = no need for co-alloc metadata, since it would get lost once converted to Box.
820+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
819821
{
820822
unsafe {
821-
RawVec::<T, A, { SHORT_TERM_VEC_PREFERS_COOP!() }>::with_capacity_zeroed_in(
823+
RawVec::<T, A, false>::with_capacity_zeroed_in(
822824
len, alloc,
823825
)
824826
.into_box(len)

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,6 @@ where
14061406
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED>
14071407
where
14081408
R: RangeBounds<usize>,
1409-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(SHORT_TERM_VEC_PREFERS_COOP!())]:,
14101409
{
14111410
// Memory safety
14121411
//

library/alloc/src/vec/into_iter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,13 @@ where
431431
{
432432
#[cfg(not(test))]
433433
fn clone(&self) -> Self {
434-
self.as_slice().to_vec_in::<A, COOP_PREFERRED>(self.alloc.deref().clone()).into_iter()
434+
// @FIXME Remove the following extras - used for type checks only
435+
let slice = self.as_slice();
436+
let vec: crate::vec::Vec<T, A, COOP_PREFERRED> = slice.to_vec_in::<A, COOP_PREFERRED>(self.alloc.deref().clone());
437+
let _iter: IntoIter<T, A, COOP_PREFERRED> = vec.into_iter();
438+
439+
//self.as_slice().to_vec_in::<A, COOP_PREFERRED>(self.alloc.deref().clone()).into_iter()
440+
loop {}
435441
}
436442
#[cfg(test)]
437443
fn clone(&self) -> Self {

library/alloc/src/vec/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,6 @@ where
20652065
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED>
20662066
where
20672067
R: RangeBounds<usize>,
2068-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(SHORT_TERM_VEC_PREFERS_COOP!())]:,
2069-
20702068
{
20712069
// Memory safety
20722070
//
@@ -2893,8 +2891,6 @@ where
28932891
impl<T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for Vec<T, A, COOP_PREFERRED>
28942892
where
28952893
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
2896-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(SHORT_TERM_VEC_PREFERS_COOP!())]:,
2897-
28982894
{
28992895
type Item = T;
29002896
type IntoIter = IntoIter<T, A, COOP_PREFERRED>;

library/alloc/src/vec/splice.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub struct Splice<
2626
const COOP_PREFERRED: bool = false
2727
> where
2828
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
29-
//FIXME: If using SHORT_TERM_VEC_PREFERS_COOP!() instead of true, and the same for `drain` below, then this failed with: `derive` cannot be used on item swith type macros
3029
{
3130
pub(super) drain: Drain<'a, I::Item, A, COOP_PREFERRED>,
3231
pub(super) replace_with: I,

0 commit comments

Comments
 (0)