@@ -190,21 +190,21 @@ inline void _Adjust_manually_vector_aligned(void*& _Ptr, size_t& _Bytes) {
190
190
}
191
191
#endif // defined(_M_IX86) || defined(_M_X64)
192
192
193
- #ifdef __cpp_aligned_new
194
- template <size_t _Align, class _Traits = _Default_allocate_traits,
195
- enable_if_t<(_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__), int> = 0>
193
+ template <size_t _Align, class _Traits = _Default_allocate_traits>
196
194
__declspec(allocator) _CONSTEXPR20 void* _Allocate(const size_t _Bytes) {
197
- // allocate _Bytes when __cpp_aligned_new && _Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
195
+ // allocate _Bytes
198
196
if (_Bytes == 0) {
199
197
return nullptr;
200
198
}
201
199
202
200
#if _HAS_CXX20 // TRANSITION, GH-1532
203
201
if (_STD is_constant_evaluated()) {
204
202
return _Traits::_Allocate(_Bytes);
205
- } else
203
+ }
206
204
#endif // _HAS_CXX20
207
- {
205
+
206
+ #ifdef __cpp_aligned_new
207
+ if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
208
208
size_t _Passed_align = _Align;
209
209
#if defined(_M_IX86) || defined(_M_X64)
210
210
if (_Bytes >= _Big_allocation_threshold) {
@@ -213,75 +213,52 @@ __declspec(allocator) _CONSTEXPR20 void* _Allocate(const size_t _Bytes) {
213
213
}
214
214
#endif // defined(_M_IX86) || defined(_M_X64)
215
215
return _Traits::_Allocate_aligned(_Bytes, _Passed_align);
216
- }
217
- }
218
-
219
- template <size_t _Align, enable_if_t<(_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__), int> = 0>
220
- _CONSTEXPR20 void _Deallocate(void* _Ptr, const size_t _Bytes) noexcept {
221
- // deallocate storage allocated by _Allocate when __cpp_aligned_new && _Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
222
- #if _HAS_CXX20 // TRANSITION, GH-1532
223
- if (_STD is_constant_evaluated()) {
224
- ::operator delete(_Ptr);
225
216
} else
226
- #endif // _HAS_CXX20
217
+ #endif // defined(__cpp_aligned_new)
227
218
{
228
- size_t _Passed_align = _Align;
229
219
#if defined(_M_IX86) || defined(_M_X64)
230
- if (_Bytes >= _Big_allocation_threshold) { // boost the alignment of big allocations to help autovectorization
231
- _Passed_align = (_STD max)(_Align, _Big_allocation_alignment);
232
- }
233
- #endif // defined(_M_IX86) || defined(_M_X64)
234
- ::operator delete(_Ptr, _Bytes, align_val_t{_Passed_align});
235
- }
236
- }
237
-
238
- #define _HAS_ALIGNED_NEW 1
239
- #else // ^^^ defined(__cpp_aligned_new) / !defined(__cpp_aligned_new) vvv
240
- #define _HAS_ALIGNED_NEW 0
241
- #endif // ^^^ !defined(__cpp_aligned_new) ^^^
242
-
243
- template <size_t _Align, class _Traits = _Default_allocate_traits,
244
- enable_if_t<(!_HAS_ALIGNED_NEW || _Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__), int> = 0>
245
- __declspec(allocator) _CONSTEXPR20 void* _Allocate(const size_t _Bytes) {
246
- // allocate _Bytes when !_HAS_ALIGNED_NEW || _Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__
247
- #if defined(_M_IX86) || defined(_M_X64)
248
- #if _HAS_CXX20 // TRANSITION, GH-1532
249
- if (!_STD is_constant_evaluated())
250
- #endif // _HAS_CXX20
251
- {
252
- if (_Bytes >= _Big_allocation_threshold) { // boost the alignment of big allocations to help autovectorization
220
+ if (_Bytes >= _Big_allocation_threshold) {
221
+ // boost the alignment of big allocations to help autovectorization
253
222
return _Allocate_manually_vector_aligned<_Traits>(_Bytes);
254
223
}
255
- }
256
224
#endif // defined(_M_IX86) || defined(_M_X64)
257
-
258
- if (_Bytes != 0) {
259
225
return _Traits::_Allocate(_Bytes);
260
226
}
261
-
262
- return nullptr;
263
227
}
264
228
265
- template <size_t _Align, enable_if_t<(!_HAS_ALIGNED_NEW || _Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__), int> = 0 >
229
+ template <size_t _Align>
266
230
_CONSTEXPR20 void _Deallocate(void* _Ptr, size_t _Bytes) noexcept {
267
- // deallocate storage allocated by _Allocate when !_HAS_ALIGNED_NEW || _Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__
231
+ // deallocate storage allocated by _Allocate
268
232
#if _HAS_CXX20 // TRANSITION, GH-1532
269
233
if (_STD is_constant_evaluated()) {
270
234
::operator delete(_Ptr);
271
- } else
235
+ return;
236
+ }
272
237
#endif // _HAS_CXX20
238
+
239
+ #ifdef __cpp_aligned_new
240
+ if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
241
+ size_t _Passed_align = _Align;
242
+ #if defined(_M_IX86) || defined(_M_X64)
243
+ if (_Bytes >= _Big_allocation_threshold) {
244
+ // boost the alignment of big allocations to help autovectorization
245
+ _Passed_align = (_STD max)(_Align, _Big_allocation_alignment);
246
+ }
247
+ #endif // defined(_M_IX86) || defined(_M_X64)
248
+ ::operator delete(_Ptr, _Bytes, align_val_t{_Passed_align});
249
+ } else
250
+ #endif // defined(__cpp_aligned_new)
273
251
{
274
252
#if defined(_M_IX86) || defined(_M_X64)
275
- if (_Bytes >= _Big_allocation_threshold) { // boost the alignment of big allocations to help autovectorization
253
+ if (_Bytes >= _Big_allocation_threshold) {
254
+ // boost the alignment of big allocations to help autovectorization
276
255
_Adjust_manually_vector_aligned(_Ptr, _Bytes);
277
256
}
278
257
#endif // defined(_M_IX86) || defined(_M_X64)
279
258
::operator delete(_Ptr, _Bytes);
280
259
}
281
260
}
282
261
283
- #undef _HAS_ALIGNED_NEW
284
-
285
262
template <class _Ptr, class _Ty>
286
263
using _Rebind_pointer_t = typename pointer_traits<_Ptr>::template rebind<_Ty>;
287
264
0 commit comments