Skip to content

Commit 23da6d9

Browse files
committed
Apply ldionne's suggestions
1 parent b439565 commit 23da6d9

File tree

8 files changed

+111
-118
lines changed

8 files changed

+111
-118
lines changed

libcxx/include/__algorithm/copy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct __copy_impl {
221221
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
222222
operator()(__bit_iterator<_Cp, _IsConst> __first,
223223
__bit_iterator<_Cp, _IsConst> __last,
224-
__bit_iterator<_Cp, false> __result) {
224+
__bit_iterator<_Cp, false> __result) const {
225225
if (__first.__ctz_ == __result.__ctz_)
226226
return std::make_pair(__last, std::__copy_aligned(__first, __last, __result));
227227
return std::make_pair(__last, std::__copy_unaligned(__first, __last, __result));

libcxx/include/__bit_reference

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ private:
869869
template <class _Dp, bool _IC>
870870
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Dp, _IC>, __bit_iterator<_Dp, false> >
871871
__copy_impl::operator()(
872-
__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
872+
__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result) const;
873873
template <class _Dp, bool _IC>
874874
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_aligned(
875875
__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);

libcxx/include/bitset

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ template <size_t N> struct hash<std::bitset<N>>;
130130
# include <__cxx03/bitset>
131131
#else
132132
# include <__algorithm/copy.h>
133-
# include <__algorithm/copy_backward.h>
134133
# include <__algorithm/count.h>
135134
# include <__algorithm/fill.h>
136135
# include <__algorithm/fill_n.h>

libcxx/test/benchmarks/algorithms/copy.bench.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <benchmark/benchmark.h>
1313
#include <vector>
1414

15-
static void bm_ranges_copy(benchmark::State& state, bool aligned) {
15+
static void bm_ranges_copy_vector_bool(benchmark::State& state, bool aligned) {
1616
auto n = state.range();
1717
std::vector<bool> in(n, true);
1818
std::vector<bool> out(aligned ? n : n + 8);
@@ -24,7 +24,7 @@ static void bm_ranges_copy(benchmark::State& state, bool aligned) {
2424
}
2525
}
2626

27-
static void bm_ranges_copy_n(benchmark::State& state, bool aligned) {
27+
static void bm_ranges_copy_n_vector_bool(benchmark::State& state, bool aligned) {
2828
auto n = state.range();
2929
std::vector<bool> in(n, true);
3030
std::vector<bool> out(aligned ? n : n + 8);
@@ -37,7 +37,7 @@ static void bm_ranges_copy_n(benchmark::State& state, bool aligned) {
3737
}
3838
}
3939

40-
static void bm_copy(benchmark::State& state, bool aligned) {
40+
static void bm_copy_vector_bool(benchmark::State& state, bool aligned) {
4141
auto n = state.range();
4242
std::vector<bool> in(n, true);
4343
std::vector<bool> out(aligned ? n : n + 8);
@@ -51,7 +51,7 @@ static void bm_copy(benchmark::State& state, bool aligned) {
5151
}
5252
}
5353

54-
static void bm_copy_n(benchmark::State& state, bool aligned) {
54+
static void bm_copy_n_vector_bool(benchmark::State& state, bool aligned) {
5555
auto n = state.range();
5656
std::vector<bool> in(n, true);
5757
std::vector<bool> out(aligned ? n : n + 8);
@@ -64,26 +64,28 @@ static void bm_copy_n(benchmark::State& state, bool aligned) {
6464
}
6565
}
6666

67-
static void bm_ranges_copy_aligned(benchmark::State& state) { bm_ranges_copy(state, true); }
68-
static void bm_ranges_copy_unaligned(benchmark::State& state) { bm_ranges_copy(state, false); }
69-
static void bm_ranges_copy_n_aligned(benchmark::State& state) { bm_ranges_copy_n(state, true); }
70-
static void bm_ranges_copy_n_unaligned(benchmark::State& state) { bm_ranges_copy_n(state, false); }
67+
static void bm_ranges_copy_aligned_vector_bool(benchmark::State& state) { bm_ranges_copy_vector_bool(state, true); }
68+
static void bm_ranges_copy_unaligned_vector_bool(benchmark::State& state) { bm_ranges_copy_vector_bool(state, false); }
69+
static void bm_ranges_copy_n_aligned_vector_bool(benchmark::State& state) { bm_ranges_copy_n_vector_bool(state, true); }
70+
static void bm_ranges_copy_n_unaligned_vector_bool(benchmark::State& state) {
71+
bm_ranges_copy_n_vector_bool(state, false);
72+
}
7173

72-
static void bm_copy_aligned(benchmark::State& state) { bm_copy(state, true); }
73-
static void bm_copy_unaligned(benchmark::State& state) { bm_copy(state, false); }
74-
static void bm_copy_n_aligned(benchmark::State& state) { bm_copy_n(state, true); }
75-
static void bm_copy_n_unaligned(benchmark::State& state) { bm_copy_n(state, false); }
74+
static void bm_copy_aligned_vector_bool(benchmark::State& state) { bm_copy_vector_bool(state, true); }
75+
static void bm_copy_unaligned_vector_bool(benchmark::State& state) { bm_copy_vector_bool(state, false); }
76+
static void bm_copy_n_aligned_vector_bool(benchmark::State& state) { bm_copy_n_vector_bool(state, true); }
77+
static void bm_copy_n_unaligned_vector_bool(benchmark::State& state) { bm_copy_n_vector_bool(state, false); }
7678

7779
// Test std::ranges::copy for vector<bool>::iterator
78-
BENCHMARK(bm_ranges_copy_aligned)->Range(8, 1 << 16)->DenseRange(102400, 204800, 4096);
79-
BENCHMARK(bm_ranges_copy_n_aligned)->Range(8, 1 << 20);
80-
BENCHMARK(bm_ranges_copy_unaligned)->Range(8, 1 << 20);
81-
BENCHMARK(bm_ranges_copy_n_unaligned)->Range(8, 1 << 20);
80+
BENCHMARK(bm_ranges_copy_aligned_vector_bool)->Range(8, 1 << 16)->DenseRange(102400, 204800, 4096);
81+
BENCHMARK(bm_ranges_copy_n_aligned_vector_bool)->Range(8, 1 << 20);
82+
BENCHMARK(bm_ranges_copy_unaligned_vector_bool)->Range(8, 1 << 20);
83+
BENCHMARK(bm_ranges_copy_n_unaligned_vector_bool)->Range(8, 1 << 20);
8284

8385
// Test std::copy for vector<bool>::iterator
84-
BENCHMARK(bm_copy_aligned)->Range(8, 1 << 20);
85-
BENCHMARK(bm_copy_n_aligned)->Range(8, 1 << 20);
86-
BENCHMARK(bm_copy_unaligned)->Range(8, 1 << 20);
87-
BENCHMARK(bm_copy_n_unaligned)->Range(8, 1 << 20);
86+
BENCHMARK(bm_copy_aligned_vector_bool)->Range(8, 1 << 20);
87+
BENCHMARK(bm_copy_n_aligned_vector_bool)->Range(8, 1 << 20);
88+
BENCHMARK(bm_copy_unaligned_vector_bool)->Range(8, 1 << 20);
89+
BENCHMARK(bm_copy_n_unaligned_vector_bool)->Range(8, 1 << 20);
8890

8991
BENCHMARK_MAIN();

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,25 @@ struct TestInIters {
6060
}
6161
};
6262

63-
template <std::size_t N>
64-
struct TestBitIter {
65-
std::vector<bool> in;
66-
TEST_CONSTEXPR_CXX20 TestBitIter() : in(N, false) {
67-
for (std::size_t i = 0; i < N; i += 2)
68-
in[i] = true;
63+
TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) {
64+
std::vector<bool> in(N, false);
65+
for (std::size_t i = 0; i < N; i += 2)
66+
in[i] = true;
67+
68+
{ // Test copy with aligned bytes
69+
std::vector<bool> out(N);
70+
std::copy(in.begin(), in.end(), out.begin());
71+
assert(in == out);
6972
}
70-
TEST_CONSTEXPR_CXX20 void operator()() {
71-
{ // Test copy with aligned bytes
72-
std::vector<bool> out(N);
73-
std::copy(in.begin(), in.end(), out.begin());
74-
assert(in == out);
75-
}
76-
{ // Test copy with unaligned bytes
77-
std::vector<bool> out(N + 8);
78-
std::copy(in.begin(), in.end(), out.begin() + 4);
79-
for (std::size_t i = 0; i < N; ++i)
80-
assert(out[i + 4] == in[i]);
81-
}
73+
{ // Test copy with unaligned bytes
74+
std::vector<bool> out(N + 8);
75+
std::copy(in.begin(), in.end(), out.begin() + 4);
76+
for (std::size_t i = 0; i < N; ++i)
77+
assert(out[i + 4] == in[i]);
8278
}
83-
};
79+
80+
return true;
81+
}
8482

8583
TEST_CONSTEXPR_CXX20 bool test() {
8684
types::for_each(types::cpp17_input_iterator_list<int*>(), TestInIters());
@@ -102,11 +100,11 @@ TEST_CONSTEXPR_CXX20 bool test() {
102100
}
103101

104102
{ // Test vector<bool>::iterator optimization
105-
TestBitIter<8>()();
106-
TestBitIter<16>()();
107-
TestBitIter<32>()();
108-
TestBitIter<64>()();
109-
TestBitIter<1024>()();
103+
assert(test_vector_bool(8));
104+
assert(test_vector_bool(16));
105+
assert(test_vector_bool(32));
106+
assert(test_vector_bool(64));
107+
assert(test_vector_bool(256));
110108
}
111109

112110
return true;

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,25 @@ TEST_CONSTEXPR_CXX20 void test_copy_n() {
6969
}
7070
}
7171

72-
template <std::size_t N>
73-
struct TestBitIter {
74-
std::vector<bool> in;
75-
TEST_CONSTEXPR_CXX20 TestBitIter() : in(N, false) {
76-
for (std::size_t i = 0; i < N; i += 2)
77-
in[i] = true;
72+
TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) {
73+
std::vector<bool> in(N, false);
74+
for (std::size_t i = 0; i < N; i += 2)
75+
in[i] = true;
76+
77+
{ // Test copy with aligned bytes
78+
std::vector<bool> out(N);
79+
std::copy_n(in.begin(), N, out.begin());
80+
assert(in == out);
7881
}
79-
TEST_CONSTEXPR_CXX20 void operator()() {
80-
{ // Test copy with aligned bytes
81-
std::vector<bool> out(N);
82-
std::copy_n(in.begin(), N, out.begin());
83-
assert(in == out);
84-
}
85-
{ // Test copy with unaligned bytes
86-
std::vector<bool> out(N + 8);
87-
std::copy_n(in.begin(), N, out.begin() + 4);
88-
for (std::size_t i = 0; i < N; ++i)
89-
assert(out[i + 4] == in[i]);
90-
}
82+
{ // Test copy with unaligned bytes
83+
std::vector<bool> out(N + 8);
84+
std::copy_n(in.begin(), N, out.begin() + 4);
85+
for (std::size_t i = 0; i < N; ++i)
86+
assert(out[i + 4] == in[i]);
9187
}
92-
};
88+
89+
return true;
90+
}
9391

9492
TEST_CONSTEXPR_CXX20 bool test() {
9593
test_copy_n<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
@@ -128,11 +126,11 @@ TEST_CONSTEXPR_CXX20 bool test() {
128126
test_copy_n<const int*, int*>();
129127

130128
{ // Test vector<bool>::iterator optimization
131-
TestBitIter<8>()();
132-
TestBitIter<16>()();
133-
TestBitIter<32>()();
134-
TestBitIter<64>()();
135-
TestBitIter<1024>()();
129+
assert(test_vector_bool(8));
130+
assert(test_vector_bool(16));
131+
assert(test_vector_bool(32));
132+
assert(test_vector_bool(64));
133+
assert(test_vector_bool(256));
136134
}
137135

138136
return true;

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.pass.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,25 @@ constexpr void test_iterators() {
101101
// clang-format on
102102

103103
#if TEST_STD_VER >= 23
104-
template <std::size_t N>
105-
struct TestBitIter {
106-
std::vector<bool> in;
107-
TEST_CONSTEXPR_CXX20 TestBitIter() : in(N, false) {
108-
for (std::size_t i = 0; i < N; i += 2)
109-
in[i] = true;
104+
constexpr bool test_vector_bool(std::size_t N) {
105+
std::vector<bool> in(N, false);
106+
for (std::size_t i = 0; i < N; i += 2)
107+
in[i] = true;
108+
109+
{ // Test copy with aligned bytes
110+
std::vector<bool> out(N);
111+
std::ranges::copy(in, out.begin());
112+
assert(in == out);
110113
}
111-
TEST_CONSTEXPR_CXX20 void operator()() {
112-
{ // Test copy with aligned bytes
113-
std::vector<bool> out(N);
114-
std::ranges::copy(in, out.begin());
115-
assert(in == out);
116-
}
117-
{ // Test copy with unaligned bytes
118-
std::vector<bool> out(N + 8);
119-
std::ranges::copy(in, out.begin() + 4);
120-
for (std::size_t i = 0; i < N; ++i)
121-
assert(out[i + 4] == in[i]);
122-
}
114+
{ // Test copy with unaligned bytes
115+
std::vector<bool> out(N + 8);
116+
std::ranges::copy(in, out.begin() + 4);
117+
for (std::size_t i = 0; i < N; ++i)
118+
assert(out[i + 4] == in[i]);
123119
}
124-
};
120+
121+
return true;
122+
}
125123
#endif
126124

127125
constexpr bool test() {
@@ -231,11 +229,11 @@ constexpr bool test() {
231229

232230
#if TEST_STD_VER >= 23
233231
{ // Test vector<bool>::iterator optimization
234-
TestBitIter<8>()();
235-
TestBitIter<16>()();
236-
TestBitIter<32>()();
237-
TestBitIter<64>()();
238-
TestBitIter<1024>()();
232+
assert(test_vector_bool(8));
233+
assert(test_vector_bool(16));
234+
assert(test_vector_bool(32));
235+
assert(test_vector_bool(64));
236+
assert(test_vector_bool(256));
239237
}
240238
#endif
241239

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,24 @@ constexpr void test_proxy_in_iterators() {
8282
}
8383

8484
#if TEST_STD_VER >= 23
85-
template <std::size_t N>
86-
struct TestBitIter {
87-
std::vector<bool> in;
88-
TEST_CONSTEXPR_CXX20 TestBitIter() : in(N, false) {
89-
for (std::size_t i = 0; i < N; i += 2)
90-
in[i] = true;
85+
constexpr bool test_vector_bool(std::size_t N) {
86+
std::vector<bool> in(N, false);
87+
for (std::size_t i = 0; i < N; i += 2)
88+
in[i] = true;
89+
90+
{ // Test copy with aligned bytes
91+
std::vector<bool> out(N);
92+
std::ranges::copy_n(in.begin(), N, out.begin());
93+
assert(in == out);
9194
}
92-
TEST_CONSTEXPR_CXX20 void operator()() {
93-
{ // Test copy with aligned bytes
94-
std::vector<bool> out(N);
95-
std::ranges::copy_n(in.begin(), N, out.begin());
96-
assert(in == out);
97-
}
98-
{ // Test copy with unaligned bytes
99-
std::vector<bool> out(N + 8);
100-
std::ranges::copy_n(in.begin(), N, out.begin() + 4);
101-
for (std::size_t i = 0; i < N; ++i)
102-
assert(out[i + 4] == in[i]);
103-
}
95+
{ // Test copy with unaligned bytes
96+
std::vector<bool> out(N + 8);
97+
std::ranges::copy_n(in.begin(), N, out.begin() + 4);
98+
for (std::size_t i = 0; i < N; ++i)
99+
assert(out[i + 4] == in[i]);
104100
}
101+
102+
return true;
105103
};
106104
#endif
107105

@@ -139,11 +137,11 @@ constexpr bool test() {
139137

140138
#if TEST_STD_VER >= 23
141139
{ // Test vector<bool>::iterator optimization
142-
TestBitIter<8>()();
143-
TestBitIter<16>()();
144-
TestBitIter<32>()();
145-
TestBitIter<64>()();
146-
TestBitIter<1024>()();
140+
assert(test_vector_bool(8));
141+
assert(test_vector_bool(16));
142+
assert(test_vector_bool(32));
143+
assert(test_vector_bool(64));
144+
assert(test_vector_bool(256));
147145
}
148146
#endif
149147

0 commit comments

Comments
 (0)