@@ -92,8 +92,8 @@ pub(crate) mod hack {
92
92
// We shouldn't add inline attribute to this since this is used in
93
93
// `vec!` macro mostly and causes perf regression. See #71204 for
94
94
// discussion and perf results.
95
- pub fn into_vec < T , A : Allocator > ( b : Box < [ T ] , A > ) -> Vec < T , A >
96
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
95
+ pub fn into_vec < T , A : Allocator , const COOP_PREFERRED : bool > ( b : Box < [ T ] , A > ) -> Vec < T , A , COOP_PREFERRED >
96
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
97
97
unsafe {
98
98
let len = b. len ( ) ;
99
99
let ( b, alloc) = Box :: into_raw_with_allocator ( b) ;
@@ -103,31 +103,31 @@ pub(crate) mod hack {
103
103
104
104
#[ cfg( not( no_global_oom_handling) ) ]
105
105
#[ inline]
106
- pub fn to_vec < T : ConvertVec , A : Allocator > ( s : & [ T ] , alloc : A ) -> Vec < T , A >
107
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
106
+ pub fn to_vec < T : ConvertVec , A : Allocator , const COOP_PREFERRED : bool > ( s : & [ T ] , alloc : A ) -> Vec < T , A , COOP_PREFERRED >
107
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
108
108
T :: to_vec ( s, alloc)
109
109
}
110
110
111
111
#[ cfg( not( no_global_oom_handling) ) ]
112
112
pub trait ConvertVec {
113
- fn to_vec < A : Allocator > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A >
113
+ fn to_vec < A : Allocator , const COOP_PREFERRED : bool > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A , COOP_PREFERRED >
114
114
where
115
115
Self : Sized ,
116
- [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : ;
116
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : ;
117
117
}
118
118
119
119
#[ cfg( not( no_global_oom_handling) ) ]
120
120
impl < T : Clone > ConvertVec for T {
121
121
#[ inline]
122
- default fn to_vec < A : Allocator > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A >
123
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
124
- struct DropGuard < ' a , T , A : Allocator >
125
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
126
- vec : & ' a mut Vec < T , A > ,
122
+ default fn to_vec < A : Allocator , const COOP_PREFERRED : bool > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A , COOP_PREFERRED >
123
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
124
+ struct DropGuard < ' a , T , A : Allocator , const COOP_PREFERRED : bool >
125
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
126
+ vec : & ' a mut Vec < T , A , COOP_PREFERRED > ,
127
127
num_init : usize ,
128
128
}
129
- impl < ' a , T , A : Allocator > Drop for DropGuard < ' a , T , A >
130
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
129
+ impl < ' a , T , A : Allocator , const COOP_PREFERRED : bool > Drop for DropGuard < ' a , T , A , COOP_PREFERRED >
130
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
131
131
#[ inline]
132
132
fn drop ( & mut self ) {
133
133
// SAFETY:
@@ -159,8 +159,8 @@ pub(crate) mod hack {
159
159
#[ cfg( not( no_global_oom_handling) ) ]
160
160
impl < T : Copy > ConvertVec for T {
161
161
#[ inline]
162
- fn to_vec < A : Allocator > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A >
163
- where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots :: < A > ( ) ] : {
162
+ fn to_vec < A : Allocator , const COOP_PREFERRED : bool > ( s : & [ Self ] , alloc : A ) -> Vec < Self , A , COOP_PREFERRED >
163
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
164
164
let mut v = Vec :: with_capacity_in ( s. len ( ) , alloc) ;
165
165
// SAFETY:
166
166
// allocated above with the capacity of `s`, and initialize to `s.len()` in
0 commit comments