diff options
author | Howard Hinnant <hhinnant@apple.com> | 2011-06-02 20:00:14 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2011-06-02 20:00:14 +0000 |
commit | 9eebe11dd5572b1af5de487427d63614d39c2031 (patch) | |
tree | 973069f5a9a4deabf49c95b03773415ce0301a77 /libcxx/include/__split_buffer | |
parent | aa318ae495e9429c71a7382e164991b0df02f763 (diff) | |
download | bcm5719-llvm-9eebe11dd5572b1af5de487427d63614d39c2031.tar.gz bcm5719-llvm-9eebe11dd5572b1af5de487427d63614d39c2031.zip |
I've become quite disatsified with the lack of noexcept specifications on container move construction, move assignment operator and swap. Without proper decoration on at least move construction, vectors of containers will have unacceptable performance. Here's the fix for deque.
llvm-svn: 132480
Diffstat (limited to 'libcxx/include/__split_buffer')
-rw-r--r-- | libcxx/include/__split_buffer | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer index ea9d3d0463e..e68b78508cc 100644 --- a/libcxx/include/__split_buffer +++ b/libcxx/include/__split_buffer @@ -47,10 +47,10 @@ public: typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref; typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref; - _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() {return __end_cap_.second();} - _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const {return __end_cap_.second();} - _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() {return __end_cap_.first();} - _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} __split_buffer(); explicit __split_buffer(__alloc_rr& __a); @@ -59,17 +59,23 @@ public: ~__split_buffer(); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - __split_buffer(__split_buffer&& __c); + __split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); - __split_buffer& operator=(__split_buffer&& __c); + __split_buffer& operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY iterator begin() {return __begin_;} - _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __begin_;} - _LIBCPP_INLINE_VISIBILITY iterator end() {return __end_;} - _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return __end_;} + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;} + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;} - _LIBCPP_INLINE_VISIBILITY void clear() {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + {__destruct_at_end(__begin_);} _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);} _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;} _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);} @@ -82,7 +88,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);} void reserve(size_type __n); - void shrink_to_fit(); + void shrink_to_fit() _NOEXCEPT; void push_front(const_reference __x); void push_back(const_reference __x); #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) @@ -120,40 +126,47 @@ public: void __destruct_at_begin(pointer __new_begin, false_type); void __destruct_at_begin(pointer __new_begin, true_type); - _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(pointer __new_last) + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());} - void __destruct_at_end(pointer __new_last, false_type); - void __destruct_at_end(pointer __new_last, true_type); + void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT; + void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT; - void swap(__split_buffer& __x); + void swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value); bool __invariants() const; private: _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(const __split_buffer& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) { __alloc() = _STD::move(__c.__alloc()); } _LIBCPP_INLINE_VISIBILITY - void __move_assign_alloc(const __split_buffer& __c, false_type) + void __move_assign_alloc(const __split_buffer& __c, false_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) {__swap_alloc(__x, __y, integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());} _LIBCPP_INLINE_VISIBILITY static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, true_type) + _NOEXCEPT_(__is_nothrow_swappable<__alloc_rr>::value) { using _STD::swap; swap(__x, __y); } _LIBCPP_INLINE_VISIBILITY - static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, false_type) + static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, false_type) _NOEXCEPT {} }; @@ -284,7 +297,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_t template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline void -__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT { while (__new_last < __end_) __alloc_traits::destroy(__alloc(), --__end_); @@ -293,7 +306,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_typ template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline void -__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT { __end_ = __new_last; } @@ -340,6 +353,7 @@ __split_buffer<_Tp, _Allocator>::~__split_buffer() template <class _Tp, class _Allocator> __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) : __first_(_STD::move(__c.__first_)), __begin_(_STD::move(__c.__begin_)), __end_(_STD::move(__c.__end_)), @@ -380,6 +394,9 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __al template <class _Tp, class _Allocator> __split_buffer<_Tp, _Allocator>& __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value) { clear(); shrink_to_fit(); @@ -399,6 +416,8 @@ __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) template <class _Tp, class _Allocator> void __split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) { _STD::swap(__first_, __x.__first_); _STD::swap(__begin_, __x.__begin_); @@ -425,7 +444,7 @@ __split_buffer<_Tp, _Allocator>::reserve(size_type __n) template <class _Tp, class _Allocator> void -__split_buffer<_Tp, _Allocator>::shrink_to_fit() +__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT { if (capacity() > size()) { @@ -612,6 +631,16 @@ __split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_SPLIT_BUFFER |