Skip to content

Commit eaa8148

Browse files
committed
Adjust for readability and performance
1 parent 1b7878a commit eaa8148

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

libcxx/include/__algorithm/is_permutation.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,31 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(
8383
_Proj1&& __proj1,
8484
_Proj2&& __proj2) {
8585
using _D1 = __iter_diff_t<_Iter1>;
86+
using _Ref1 = typename iterator_traits<_Iter1>::reference;
87+
using _Ref2 = typename iterator_traits<_Iter2>::reference;
88+
__identity __ident;
8689

8790
for (auto __i = __first1; __i != __last1; ++__i) {
8891
// Have we already counted the number of *__i in [f1, l1)?
89-
auto __match = std::find_if(__first1, __i, [&](typename iterator_traits<_Iter1>::reference __x) -> bool {
92+
auto __match = std::find_if(__first1, __i, [&](_Ref1 __x) -> bool {
9093
return std::__invoke(__pred, std::__invoke(__proj1, __x), std::__invoke(__proj1, *__i));
9194
});
9295

9396
if (__match == __i) {
9497
// Count number of *__i in [f2, l2)
95-
__identity __ident1;
96-
auto __predicate1 = [&](typename iterator_traits<_Iter2>::reference __x) -> bool {
98+
auto __predicate2 = [&](_Ref2 __x) -> bool {
9799
return std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj2, __x));
98100
};
99-
_D1 __c2 = std::__count_if<_AlgPolicy>(__first2, __last2, __predicate1, __ident1);
101+
_D1 __c2 = std::__count_if<_AlgPolicy>(__first2, __last2, __predicate2, __ident);
100102
if (__c2 == 0)
101103
return false;
102104

103105
// Count number of *__i in [__i, l1) (we can start with 1)
104-
__identity __ident2;
105-
auto __predicate2 = [&](typename iterator_traits<_Iter1>::reference __x) -> bool {
106+
auto __predicate1 = [&](_Ref1 __x) -> bool {
106107
return std::__invoke(__pred, std::__invoke(__proj1, *__i), std::__invoke(__proj1, __x));
107108
};
108109
auto __start = _IterOps<_AlgPolicy>::next(__i);
109-
_D1 __c1 = std::__count_if<_AlgPolicy>(__start, __last1, __predicate2, __ident2);
110-
__c1 += 1;
110+
_D1 __c1 = 1 + std::__count_if<_AlgPolicy>(__start, __last1, __predicate1, __ident);
111111
if (__c1 != __c2)
112112
return false;
113113
}

0 commit comments

Comments
 (0)