diff options
author | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2022-03-07 19:46:06 +0300 |
---|---|---|
committer | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2022-03-07 23:44:10 +0300 |
commit | 844a9c0ef4543bb8d41e56290d47ea0a80fb110b (patch) | |
tree | 2b17cf3b1fe734494c3e695b5af3dfd22fd2d049 /libcxx | |
parent | 1067f2177aa69dca0b9ffef57f5017c28cf9aed3 (diff) |
[libc++] Make common_iterator's proxy types into aggregates.
Saves one move in each case, which is basically nothing perf-wise;
this is more about simplifying the code.
Differential Revision: https://reviews.llvm.org/D121130
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/__iterator/common_iterator.h | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h index abbd8f4038fb..29dfabff8a88 100644 --- a/libcxx/include/__iterator/common_iterator.h +++ b/libcxx/include/__iterator/common_iterator.h @@ -37,31 +37,18 @@ concept __can_use_postfix_proxy = template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent> requires (!same_as<_Iter, _Sent> && copyable<_Iter>) class common_iterator { - class __proxy { - friend common_iterator; - - iter_value_t<_Iter> __value; - // We can move __x because the only caller verifies that __x is not a reference. - constexpr explicit __proxy(iter_reference_t<_Iter>&& __x) - : __value(_VSTD::move(__x)) {} - - public: + struct __proxy { constexpr const iter_value_t<_Iter>* operator->() const noexcept { - return _VSTD::addressof(__value); + return _VSTD::addressof(__value_); } + iter_value_t<_Iter> __value_; }; - class __postfix_proxy { - friend common_iterator; - - iter_value_t<_Iter> __value; - constexpr explicit __postfix_proxy(iter_reference_t<_Iter>&& __x) - : __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {} - - public: + struct __postfix_proxy { constexpr const iter_value_t<_Iter>& operator*() const noexcept { - return __value; + return __value_; } + iter_value_t<_Iter> __value_; }; public: @@ -133,7 +120,7 @@ public: auto&& __tmp = *_VSTD::__unchecked_get<_Iter>(__hold_); return _VSTD::addressof(__tmp); } else { - return __proxy(*_VSTD::__unchecked_get<_Iter>(__hold_)); + return __proxy{*_VSTD::__unchecked_get<_Iter>(__hold_)}; } } @@ -152,7 +139,7 @@ public: !__can_use_postfix_proxy<_Iter>) { return _VSTD::__unchecked_get<_Iter>(__hold_)++; } else { - __postfix_proxy __p(**this); + auto __p = __postfix_proxy{**this}; ++*this; return __p; } |