[libcxx-commits] [libcxx] 4eab04f - [libc++] Remove a bunch of conditionals on _LIBCPP_DEBUG_LEVEL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 6 06:54:43 PDT 2022
Author: Louis Dionne
Date: 2022-06-06T09:54:26-04:00
New Revision: 4eab04f8491ab4fb8456eea9a73657701c554625
URL: https://github.com/llvm/llvm-project/commit/4eab04f8491ab4fb8456eea9a73657701c554625
DIFF: https://github.com/llvm/llvm-project/commit/4eab04f8491ab4fb8456eea9a73657701c554625.diff
LOG: [libc++] Remove a bunch of conditionals on _LIBCPP_DEBUG_LEVEL
Instead of providing two different constructors for iterators that
support the debug mode, provide a single constructor but leave the
container parameter unused when the debug mode is not enabled.
This allows simplifying all the call sites to unconditionally pass
the container, which removes a bunch of duplication in the container's
implementation.
Note that this patch does add some complexity to std::span, however
that is only because std::span has the ability to use raw pointers
as iterators instead of __wrap_iter. In retrospect, I believe it was
a mistake to provide that capability, and so it will be removed in a
future patch, along with the complexity added by this patch.
Differential Revision: https://reviews.llvm.org/D126993
Added:
Modified:
libcxx/include/__hash_table
libcxx/include/__iterator/wrap_iter.h
libcxx/include/list
libcxx/include/span
libcxx/include/string
libcxx/include/vector
Removed:
################################################################################
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index a1a4d4455d58d..eaef97a798588 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -360,19 +360,15 @@ public:
{return !(__x == __y);}
private:
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
: __node_(__node)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
- }
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __hash_iterator(__next_pointer __node) _NOEXCEPT
- : __node_(__node)
- {}
#endif
+ }
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
@@ -478,19 +474,15 @@ public:
{return !(__x == __y);}
private:
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
: __node_(__node)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
- }
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __hash_const_iterator(__next_pointer __node) _NOEXCEPT
- : __node_(__node)
- {}
#endif
+ }
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
@@ -591,7 +583,6 @@ public:
{return !(__x == __y);}
private:
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __hash_local_iterator(__next_pointer __node, size_t __bucket,
size_t __bucket_count, const void* __c) _NOEXCEPT
@@ -599,22 +590,13 @@ private:
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
+#endif
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __hash_local_iterator(__next_pointer __node, size_t __bucket,
- size_t __bucket_count) _NOEXCEPT
- : __node_(__node),
- __bucket_(__bucket),
- __bucket_count_(__bucket_count)
- {
- if (__node_ != nullptr)
- __node_ = __node_->__next_;
- }
-#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
@@ -734,7 +716,6 @@ public:
{return !(__x == __y);}
private:
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
size_t __bucket_count, const void* __c) _NOEXCEPT
@@ -742,22 +723,13 @@ private:
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
+#endif
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
- size_t __bucket_count) _NOEXCEPT
- : __node_(__node_ptr),
- __bucket_(__bucket),
- __bucket_count_(__bucket_count)
- {
- if (__node_ != nullptr)
- __node_ = __node_->__next_;
- }
-#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
};
@@ -1279,11 +1251,7 @@ public:
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::begin(n) called with n >= bucket_count()");
-#if _LIBCPP_DEBUG_LEVEL == 2
return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
-#else
- return local_iterator(__bucket_list_[__n], __n, bucket_count());
-#endif
}
_LIBCPP_INLINE_VISIBILITY
@@ -1292,11 +1260,7 @@ public:
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::end(n) called with n >= bucket_count()");
-#if _LIBCPP_DEBUG_LEVEL == 2
return local_iterator(nullptr, __n, bucket_count(), this);
-#else
- return local_iterator(nullptr, __n, bucket_count());
-#endif
}
_LIBCPP_INLINE_VISIBILITY
@@ -1305,11 +1269,7 @@ public:
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::cbegin(n) called with n >= bucket_count()");
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
-#else
- return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
-#endif
}
_LIBCPP_INLINE_VISIBILITY
@@ -1318,11 +1278,7 @@ public:
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::cend(n) called with n >= bucket_count()");
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_local_iterator(nullptr, __n, bucket_count(), this);
-#else
- return const_local_iterator(nullptr, __n, bucket_count());
-#endif
}
#if _LIBCPP_DEBUG_LEVEL == 2
@@ -1765,11 +1721,7 @@ inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__p1_.first().__next_, this);
-#else
- return iterator(__p1_.first().__next_);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1777,11 +1729,7 @@ inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(nullptr, this);
-#else
- return iterator(nullptr);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1789,11 +1737,7 @@ inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_iterator(__p1_.first().__next_, this);
-#else
- return const_iterator(__p1_.first().__next_);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1801,11 +1745,7 @@ inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_iterator(nullptr, this);
-#else
- return const_iterator(nullptr);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1910,11 +1850,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __
__existing_node = __nd->__ptr();
__inserted = true;
}
-#if _LIBCPP_DEBUG_LEVEL == 2
return pair<iterator, bool>(iterator(__existing_node, this), __inserted);
-#else
- return pair<iterator, bool>(iterator(__existing_node), __inserted);
-#endif
}
// Prepare the container for an insertion of the value __cp_val with the hash
@@ -2008,11 +1944,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c
__next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_);
__node_insert_multi_perform(__cp, __pn);
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__cp->__ptr(), this);
-#else
- return iterator(__cp->__ptr());
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -2041,11 +1973,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
__cp->__next_ = __np;
__pp->__next_ = static_cast<__next_pointer>(__cp);
++size();
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(static_cast<__next_pointer>(__cp), this);
-#else
- return iterator(static_cast<__next_pointer>(__cp));
-#endif
}
return __node_insert_multi(__cp);
}
@@ -2111,11 +2039,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const&
__inserted = true;
}
__done:
-#if _LIBCPP_DEBUG_LEVEL == 2
return pair<iterator, bool>(iterator(__nd, this), __inserted);
-#else
- return pair<iterator, bool>(iterator(__nd), __inserted);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -2386,11 +2310,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
{
if ((__nd->__hash() == __hash)
&& key_eq()(__nd->__upcast()->__value_, __k))
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__nd, this);
-#else
- return iterator(__nd);
-#endif
}
}
}
@@ -2417,11 +2337,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
{
if ((__nd->__hash() == __hash)
&& key_eq()(__nd->__upcast()->__value_, __k))
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_iterator(__nd, this);
-#else
- return const_iterator(__nd);
-#endif
}
}
@@ -2474,11 +2390,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
" referring to this container");
_LIBCPP_ASSERT(__p != end(),
"unordered container erase(iterator) called with a non-dereferenceable iterator");
-#if _LIBCPP_DEBUG_LEVEL == 2
iterator __r(__np, this);
-#else
- iterator __r(__np);
-#endif
++__r;
remove(__p);
return __r;
@@ -2501,11 +2413,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
erase(__p);
}
__next_pointer __np = __last.__node_;
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator (__np, this);
-#else
- return iterator (__np);
-#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 69e5ee15aab25..a3f42ca77352c 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -135,17 +135,15 @@ class __wrap_iter
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator_type base() const _NOEXCEPT {return __i;}
private:
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
- explicit __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
+ explicit __wrap_iter(const void* __p, iterator_type __x) _NOEXCEPT : __i(__x)
{
+ (void)__p;
+#if _LIBCPP_DEBUG_LEVEL == 2
if (!__libcpp_is_constant_evaluated())
__get_db()->__insert_ic(this, __p);
- }
-#else
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
- explicit __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
#endif
+ }
template <class _Up> friend class __wrap_iter;
template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
diff --git a/libcxx/include/list b/libcxx/include/list
index 3dffcdd1f829a..bcca7f0c67bb6 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -299,19 +299,15 @@ class _LIBCPP_TEMPLATE_VIS __list_iterator
__link_pointer __ptr_;
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
: __ptr_(__p)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
- }
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
#endif
-
-
+ }
template<class, class> friend class list;
template<class, class> friend class __list_imp;
@@ -412,17 +408,15 @@ class _LIBCPP_TEMPLATE_VIS __list_const_iterator
__link_pointer __ptr_;
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_INLINE_VISIBILITY
explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
: __ptr_(__p)
{
+ (void)__c;
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_ic(this, __c);
- }
-#else
- _LIBCPP_INLINE_VISIBILITY
- explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
#endif
+ }
template<class, class> friend class list;
template<class, class> friend class __list_imp;
@@ -600,38 +594,22 @@ protected:
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__end_.__next_, this);
-#else
- return iterator(__end_.__next_);
-#endif
}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_iterator(__end_.__next_, this);
-#else
- return const_iterator(__end_.__next_);
-#endif
}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__end_as_link(), this);
-#else
- return iterator(__end_as_link());
-#endif
}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{
-#if _LIBCPP_DEBUG_LEVEL == 2
return const_iterator(__end_as_link(), this);
-#else
- return const_iterator(__end_as_link());
-#endif
}
void swap(__list_imp& __c)
@@ -1401,11 +1379,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
++base::__sz();
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__hold.release()->__as_link(), this);
-#else
- return iterator(__hold.release()->__as_link());
-#endif
}
template <class _Tp, class _Alloc>
@@ -1414,11 +1388,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
{
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"list::insert(iterator, n, x) called with an iterator not referring to this list");
-#if _LIBCPP_DEBUG_LEVEL == 2
iterator __r(__p.__ptr_, this);
-#else
- iterator __r(__p.__ptr_);
-#endif
if (__n > 0)
{
size_type __ds = 0;
@@ -1426,11 +1396,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
++__ds;
-#if _LIBCPP_DEBUG_LEVEL == 2
__r = iterator(__hold->__as_link(), this);
-#else
- __r = iterator(__hold->__as_link());
-#endif
__hold.release();
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -1456,11 +1422,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
-#if _LIBCPP_DEBUG_LEVEL == 2
__e = iterator(__prev, this);
-#else
- __e = iterator(__prev);
-#endif
}
throw;
}
@@ -1479,11 +1441,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
{
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"list::insert(iterator, range) called with an iterator not referring to this list");
-#if _LIBCPP_DEBUG_LEVEL == 2
iterator __r(__p.__ptr_, this);
-#else
- iterator __r(__p.__ptr_);
-#endif
if (__f != __l)
{
size_type __ds = 0;
@@ -1491,11 +1449,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
++__ds;
-#if _LIBCPP_DEBUG_LEVEL == 2
__r = iterator(__hold.get()->__as_link(), this);
-#else
- __r = iterator(__hold.get()->__as_link());
-#endif
__hold.release();
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -1521,11 +1475,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
-#if _LIBCPP_DEBUG_LEVEL == 2
__e = iterator(__prev, this);
-#else
- __e = iterator(__prev);
-#endif
}
throw;
}
@@ -1644,11 +1594,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
__link_nodes(__p.__ptr_, __nl, __nl);
++base::__sz();
__hold.release();
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__nl, this);
-#else
- return iterator(__nl);
-#endif
}
template <class _Tp, class _Alloc>
@@ -1664,11 +1610,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
__link_nodes(__p.__ptr_, __nl, __nl);
++base::__sz();
__hold.release();
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__nl, this);
-#else
- return iterator(__nl);
-#endif
}
#endif // _LIBCPP_CXX03_LANG
@@ -1762,11 +1704,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p)
__node_pointer __np = __n->__as_node();
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__r, this);
-#else
- return iterator(__r);
-#endif
}
template <class _Tp, class _Alloc>
@@ -1806,11 +1744,7 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
__node_alloc_traits::deallocate(__na, __np, 1);
}
}
-#if _LIBCPP_DEBUG_LEVEL == 2
return iterator(__l.__ptr_, this);
-#else
- return iterator(__l.__ptr_);
-#endif
}
template <class _Tp, class _Alloc>
@@ -1827,11 +1761,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
++__ds;
-#if _LIBCPP_DEBUG_LEVEL == 2
iterator __r = iterator(__hold.release()->__as_link(), this);
-#else
- iterator __r = iterator(__hold.release()->__as_link());
-#endif
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
@@ -1856,11 +1786,7 @@ list<_Tp, _Alloc>::resize(size_type __n)
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
-#if _LIBCPP_DEBUG_LEVEL == 2
__e = iterator(__prev, this);
-#else
- __e = iterator(__prev);
-#endif
}
throw;
}
@@ -1885,11 +1811,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
++__ds;
__link_pointer __nl = __hold.release()->__as_link();
-#if _LIBCPP_DEBUG_LEVEL == 2
iterator __r = iterator(__nl, this);
-#else
- iterator __r = iterator(__nl);
-#endif
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
@@ -1914,11 +1836,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
-#if _LIBCPP_DEBUG_LEVEL == 2
__e = iterator(__prev, this);
-#else
- __e = iterator(__prev);
-#endif
}
throw;
}
diff --git a/libcxx/include/span b/libcxx/include/span
index 15564d8378523..e65af7971e5f2 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -197,6 +197,10 @@ concept __span_compatible_range =
is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
+# define _LIBCPP_SPAN_USE_POINTER_ITERATOR
+#endif
+
template <typename _Tp, size_t _Extent>
class _LIBCPP_TEMPLATE_VIS span {
public:
@@ -209,7 +213,7 @@ public:
using const_pointer = const _Tp *;
using reference = _Tp &;
using const_reference = const _Tp &;
-#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
using iterator = pointer;
#else
using iterator = __wrap_iter<pointer>;
@@ -381,8 +385,20 @@ public:
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
// [span.iter], span iterator support
- _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
- _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
+ _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
+ return iterator(data());
+#else
+ return iterator(this, data());
+#endif
+ }
+ _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept {
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
+ return iterator(data() + size());
+#else
+ return iterator(this, data() + size());
+#endif
+ }
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
@@ -412,7 +428,7 @@ public:
using const_pointer = const _Tp *;
using reference = _Tp &;
using const_reference = const _Tp &;
-#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
using iterator = pointer;
#else
using iterator = __wrap_iter<pointer>;
@@ -560,8 +576,20 @@ public:
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
// [span.iter], span iterator support
- _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
- _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
+ _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
+ return iterator(data());
+#else
+ return iterator(this, data());
+#endif
+ }
+ _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept {
+#ifdef _LIBCPP_SPAN_USE_POINTER_ITERATOR
+ return iterator(data() + size());
+#else
+ return iterator(this, data() + size());
+#endif
+ }
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
diff --git a/libcxx/include/string b/libcxx/include/string
index e3fe06b50d2b9..86370e5260a5b 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -900,7 +900,6 @@ public:
#endif
_LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(value_type __c);
-#if _LIBCPP_DEBUG_LEVEL == 2
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
iterator begin() _NOEXCEPT
{return iterator(this, __get_pointer());}
@@ -913,20 +912,7 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
const_iterator end() const _NOEXCEPT
{return const_iterator(this, __get_pointer() + size());}
-#else
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
- iterator begin() _NOEXCEPT
- {return iterator(__get_pointer());}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
- const_iterator begin() const _NOEXCEPT
- {return const_iterator(__get_pointer());}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
- iterator end() _NOEXCEPT
- {return iterator(__get_pointer() + size());}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
- const_iterator end() const _NOEXCEPT
- {return const_iterator(__get_pointer() + size());}
-#endif // _LIBCPP_DEBUG_LEVEL == 2
+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
diff --git a/libcxx/include/vector b/libcxx/include/vector
index d327e2827938e..e522c1a842bde 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -1361,36 +1361,12 @@ vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
std::__debug_db_invalidate_all(this);
}
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::iterator
-vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
- return iterator(this, __p);
-#else
- return iterator(__p);
-#endif
-}
-
-template <class _Tp, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-typename vector<_Tp, _Allocator>::const_iterator
-vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
-{
-#if _LIBCPP_DEBUG_LEVEL == 2
- return const_iterator(this, __p);
-#else
- return const_iterator(__p);
-#endif
-}
-
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::begin() _NOEXCEPT
{
- return __make_iter(this->__begin_);
+ return iterator(this, this->__begin_);
}
template <class _Tp, class _Allocator>
@@ -1398,7 +1374,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::begin() const _NOEXCEPT
{
- return __make_iter(this->__begin_);
+ return const_iterator(this, this->__begin_);
}
template <class _Tp, class _Allocator>
@@ -1406,7 +1382,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::end() _NOEXCEPT
{
- return __make_iter(this->__end_);
+ return iterator(this, this->__end_);
}
template <class _Tp, class _Allocator>
@@ -1414,7 +1390,7 @@ inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::end() const _NOEXCEPT
{
- return __make_iter(this->__end_);
+ return const_iterator(this, this->__end_);
}
template <class _Tp, class _Allocator>
@@ -1584,7 +1560,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __position)
pointer __p = this->__begin_ + __ps;
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
this->__invalidate_iterators_past(__p-1);
- iterator __r = __make_iter(__p);
+ iterator __r = iterator(this, __p);
return __r;
}
@@ -1603,7 +1579,7 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
this->__invalidate_iterators_past(__p - 1);
}
- iterator __r = __make_iter(__p);
+ iterator __r = iterator(this, __p);
return __r;
}
@@ -1655,7 +1631,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
__v.push_back(__x);
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1684,7 +1660,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
__v.push_back(_VSTD::move(__x));
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1715,7 +1691,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
__v.emplace_back(_VSTD::forward<_Args>(__args)...);
__p = __swap_out_circular_buffer(__v, __p);
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1754,7 +1730,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
__p = __swap_out_circular_buffer(__v, __p);
}
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
@@ -1797,14 +1773,14 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __firs
}
catch (...)
{
- erase(__make_iter(__old_last), end());
+ erase(iterator(this, __old_last), end());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = _VSTD::rotate(__p, __old_last, this->__end_);
- insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
- _VSTD::make_move_iterator(__v.end()));
+ insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
+ _VSTD::make_move_iterator(__v.end()));
return begin() + __off;
}
@@ -1854,7 +1830,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __fi
__p = __swap_out_circular_buffer(__v, __p);
}
}
- return __make_iter(__p);
+ return iterator(this, __p);
}
template <class _Tp, class _Allocator>
More information about the libcxx-commits
mailing list