Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 20 additions & 46 deletions libcxx/include/__hash_table
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/pair.h>
#include <__utility/scope_guard.h>
#include <__utility/swap.h>
#include <__utility/try_key_extraction.h>
#include <limits>
Expand Down Expand Up @@ -1317,23 +1318,14 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
max_load_factor() = __u.max_load_factor();
if (bucket_count() != 0) {
__next_pointer __cache = __detach();
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
const_iterator __i = __u.begin();
while (__cache != nullptr && __u.size() != 0) {
__assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value()));
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__deallocate_node(__cache);
throw;
auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
const_iterator __i = __u.begin();
while (__cache != nullptr && __u.size() != 0) {
__assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value()));
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__deallocate_node(__cache);
}
const_iterator __i = __u.begin();
while (__u.size() != 0)
Expand Down Expand Up @@ -1361,22 +1353,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __

if (bucket_count() != 0) {
__next_pointer __cache = __detach();
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
for (; __cache != nullptr && __first != __last; ++__first) {
__assign_value(__cache->__upcast()->__get_value(), *__first);
__next_pointer __next = __cache->__next_;
__node_insert_unique(__cache->__upcast());
__cache = __next;
}
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__deallocate_node(__cache);
throw;
auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
for (; __cache != nullptr && __first != __last; ++__first) {
__assign_value(__cache->__upcast()->__get_value(), *__first);
__next_pointer __next = __cache->__next_;
__node_insert_unique(__cache->__upcast());
__cache = __next;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__emplace_unique(*__first);
Expand All @@ -1391,22 +1374,13 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
"__assign_multi may only be called with the containers value type or the nodes value type");
if (bucket_count() != 0) {
__next_pointer __cache = __detach();
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
for (; __cache != nullptr && __first != __last; ++__first) {
__assign_value(__cache->__upcast()->__get_value(), *__first);
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__deallocate_node(__cache);
throw;
auto __guard = std::__make_scope_guard([&] { __deallocate_node(__cache); });
for (; __cache != nullptr && __first != __last; ++__first) {
__assign_value(__cache->__upcast()->__get_value(), *__first);
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__emplace_multi(*__first);
Expand Down
93 changes: 33 additions & 60 deletions libcxx/include/__memory/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <__type_traits/remove_extent.h>
#include <__type_traits/remove_reference.h>
#include <__utility/declval.h>
#include <__utility/exception_guard.h>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/swap.h>
Expand Down Expand Up @@ -352,52 +353,38 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {

template <class _Yp, class _Dp, __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) {
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
auto __guard = std::__make_exception_guard([&] { __d(__p); });
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
#ifndef _LIBCPP_CXX03_LANG
__cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
__cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
#else
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
#endif // not _LIBCPP_CXX03_LANG
__enable_weak_this(__p, __p);
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__d(__p);
throw;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__enable_weak_this(__p, __p);
__guard.__complete();
}

template <class _Yp,
class _Dp,
class _Alloc,
__enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) {
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new ((void*)std::addressof(*__hold2.get()))
auto __guard = std::__make_exception_guard([&] { __d(__p); });
typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new ((void*)std::addressof(*__hold2.get()))
#ifndef _LIBCPP_CXX03_LANG
_CntrlBlk(__p, std::move(__d), __a);
_CntrlBlk(__p, std::move(__d), __a);
#else
_CntrlBlk(__p, __d, __a);
#endif // not _LIBCPP_CXX03_LANG
__cntrl_ = std::addressof(*__hold2.release());
__enable_weak_this(__p, __p);
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__d(__p);
throw;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__cntrl_ = std::addressof(*__hold2.release());
__enable_weak_this(__p, __p);
__guard.__complete();
}

template <class _Dp>
Expand All @@ -406,22 +393,15 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {
_Dp __d,
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
: __ptr_(nullptr) {
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
auto __guard = std::__make_exception_guard([&] { __d(__p); });
typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
#ifndef _LIBCPP_CXX03_LANG
__cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
__cntrl_ = new _CntrlBlk(__p, std::move(__d), _AllocT());
#else
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
#endif // not _LIBCPP_CXX03_LANG
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__d(__p);
throw;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__guard.__complete();
}

template <class _Dp, class _Alloc>
Expand All @@ -431,27 +411,20 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {
_Alloc __a,
__enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
: __ptr_(nullptr) {
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new ((void*)std::addressof(*__hold2.get()))
auto __guard = std::__make_exception_guard([&] { __d(__p); });
typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new ((void*)std::addressof(*__hold2.get()))
#ifndef _LIBCPP_CXX03_LANG
_CntrlBlk(__p, std::move(__d), __a);
_CntrlBlk(__p, std::move(__d), __a);
#else
_CntrlBlk(__p, __d, __a);
#endif // not _LIBCPP_CXX03_LANG
__cntrl_ = std::addressof(*__hold2.release());
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__d(__p);
throw;
}
#endif // _LIBCPP_HAS_EXCEPTIONS
__cntrl_ = std::addressof(*__hold2.release());
__guard.__complete();
}

template <class _Yp>
Expand Down
Loading
Loading