14
14
#include <xmemory>
15
15
#include <xstddef>
16
16
#if _HAS_CXX17
17
- #include <memory>
18
17
#include <unordered_map>
19
18
#endif // _HAS_CXX17
20
19
#ifdef __cpp_lib_concepts
@@ -2176,12 +2175,6 @@ _Ty* _Decode_aligned_block(void*& _Base, const size_t _Count) {
2176
2175
return static_cast<_Ty*>(_Decode_aligned_block(_Base, sizeof(_Ty) * _Count, alignof(_Ty)));
2177
2176
}
2178
2177
2179
- struct _Global_delete {
2180
- void operator()(void* const _Ptr) const {
2181
- ::operator delete(_Ptr);
2182
- }
2183
- };
2184
-
2185
2178
template <class _FwdItHaystack, class _FwdItPat, class _Pred_eq>
2186
2179
_CONSTEXPR20 pair<_FwdItHaystack, _FwdItHaystack> _Search_pair_unchecked(
2187
2180
_FwdItHaystack _First1, _FwdItHaystack _Last1, _FwdItPat _First2, _FwdItPat _Last2, _Pred_eq& _Eq) {
@@ -2325,6 +2318,41 @@ private:
2325
2318
_Diff _Table[_Limit];
2326
2319
};
2327
2320
2321
+ // _Mini_ptr avoids needing to include <memory> which includes <atomic>.
2322
+ // It doesn't attempt to provide all of unique_ptr's safety features; use carefully.
2323
+ enum class _Deletion_kind { _Global_scalar, _Normal_array };
2324
+
2325
+ template <class _Ty, _Deletion_kind _Del>
2326
+ class _Mini_ptr {
2327
+ public:
2328
+ explicit _Mini_ptr(_Ty* const _Ptr_) noexcept : _Ptr(_Ptr_) {}
2329
+
2330
+ ~_Mini_ptr() noexcept {
2331
+ if (_Ptr) {
2332
+ if constexpr (_Del == _Deletion_kind::_Global_scalar) {
2333
+ ::operator delete(_Ptr);
2334
+ } else if constexpr (_Del == _Deletion_kind::_Normal_array) {
2335
+ delete[] _Ptr;
2336
+ } else {
2337
+ static_assert(_Always_false<_Ty>, "Unknown _Deletion_kind.");
2338
+ }
2339
+ }
2340
+ }
2341
+
2342
+ _NODISCARD _Ty* _Get() const noexcept {
2343
+ return _Ptr;
2344
+ }
2345
+
2346
+ _NODISCARD _Ty* _Release() noexcept {
2347
+ return _STD exchange(_Ptr, nullptr);
2348
+ }
2349
+
2350
+ _Mini_ptr(const _Mini_ptr&) = delete;
2351
+ _Mini_ptr& operator=(const _Mini_ptr&) = delete;
2352
+
2353
+ private:
2354
+ _Ty* _Ptr;
2355
+ };
2328
2356
2329
2357
template <class _RanItPat, class _Pred_eq>
2330
2358
void _Build_boyer_moore_delta_2_table(_Iter_diff_t<_RanItPat>* const _Shifts, const _RanItPat _Pat_first,
@@ -2345,7 +2373,8 @@ void _Build_boyer_moore_delta_2_table(_Iter_diff_t<_RanItPat>* const _Shifts, co
2345
2373
2346
2374
const auto _Mx = static_cast<size_t>(_Pat_size);
2347
2375
2348
- const unique_ptr<size_t[]> _Fx{new size_t[_Mx]};
2376
+ const _Mini_ptr<size_t, _Deletion_kind::_Normal_array> _Fx_ptr{new size_t[_Mx]};
2377
+ size_t* const _Fx = _Fx_ptr._Get();
2349
2378
2350
2379
for (size_t _Kx = 1; _Kx <= _Mx; ++_Kx) {
2351
2380
_Shifts[_Kx - 1] = static_cast<_Diff>(2 * _Mx - _Kx);
@@ -2496,8 +2525,8 @@ struct _Single_delta1_type_boyer_moore_traits {
2496
2525
_Add_alloc_size<_Diff>(_Buf_size, _Pat_size);
2497
2526
}
2498
2527
2499
- unique_ptr <void, _Global_delete > _Buf_bytes(::operator new(_Buf_size));
2500
- void* _Buf = _Buf_bytes.get ();
2528
+ _Mini_ptr <void, _Deletion_kind::_Global_scalar > _Buf_bytes(::operator new(_Buf_size));
2529
+ void* _Buf = _Buf_bytes._Get ();
2501
2530
*_Decode_aligned_block<_Atomic_counter_t>(_Buf) = 1;
2502
2531
void* const _Delta1 = _Decode_aligned_block<_Delta1_t>(_Buf);
2503
2532
if (_Build_delta2) {
@@ -2506,7 +2535,7 @@ struct _Single_delta1_type_boyer_moore_traits {
2506
2535
}
2507
2536
2508
2537
::new (_Delta1) _Delta1_t(_First, _UFirst, _Pat_size_raw, _STD move(_Hash_fn), _STD move(_Eq));
2509
- return _Buf_bytes.release ();
2538
+ return _Buf_bytes._Release ();
2510
2539
}
2511
2540
2512
2541
template <class _RanItHaystack>
@@ -2590,8 +2619,8 @@ struct _Boyer_moore_traits_wchar_t_mode {
2590
2619
_Add_alloc_size<_Diff>(_Buf_size, _Pat_size);
2591
2620
}
2592
2621
2593
- unique_ptr <void, _Global_delete > _Buf_bytes(::operator new(_Buf_size));
2594
- void* _Buf = _Buf_bytes.get ();
2622
+ _Mini_ptr <void, _Deletion_kind::_Global_scalar > _Buf_bytes(::operator new(_Buf_size));
2623
+ void* _Buf = _Buf_bytes._Get ();
2595
2624
*_Decode_aligned_block<_Atomic_counter_t>(_Buf) = 1;
2596
2625
*_Decode_aligned_block<bool>(_Buf) = _Use_large_table;
2597
2626
if (_Use_large_table) {
@@ -2610,7 +2639,7 @@ struct _Boyer_moore_traits_wchar_t_mode {
2610
2639
_Decode_aligned_block<_Diff>(_Buf, _Pat_size), _UFirst, _Pat_size_raw, _Eq);
2611
2640
}
2612
2641
2613
- return _Buf_bytes.release ();
2642
+ return _Buf_bytes._Release ();
2614
2643
}
2615
2644
2616
2645
template <class _RanItHaystack>
0 commit comments