Skip to content

Commit 5aa03b6

Browse files
committed
[libc++][NFC] Apply clang-format on large parts of the code base
This commit does a pass of clang-format over files in libc++ that don't require major changes to conform to our style guide, or for which we're not overly concerned about conflicting with in-flight patches or hindering the git blame. This roughly covers: - benchmarks - range algorithms - concepts - type traits I did a manual verification of all the changes, and in particular I applied clang-format on/off annotations in a few places where the result was less readable after than before. This was not necessary in a lot of places, however I did find that clang-format had pretty bad taste when it comes to formatting concepts. Differential Revision: https://reviews.llvm.org/D153140
1 parent 923dbb0 commit 5aa03b6

File tree

263 files changed

+3365
-4090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+3365
-4090
lines changed

Diff for: libcxx/benchmarks/CartesianBenchmarks.h

+10-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
109
#include <string>
1110
#include <tuple>
1211
#include <type_traits>
@@ -22,7 +21,7 @@ struct EnumValue : std::integral_constant<E, static_cast<E>(I)> {
2221
static std::string name() { return std::string("_") + D::Names[I]; }
2322
};
2423

25-
template <class D, class E, size_t ...Idxs>
24+
template <class D, class E, size_t... Idxs>
2625
constexpr auto makeEnumValueTuple(std::index_sequence<Idxs...>) {
2726
return std::make_tuple(EnumValue<D, E, Idxs>{}...);
2827
}
@@ -41,8 +40,7 @@ void makeBenchmarkFromValuesImpl(const Args& A, std::index_sequence<Is...>) {
4140
for (auto& V : A) {
4241
B Bench{std::get<Is>(V)...};
4342
if (!internal::skip(Bench, 0)) {
44-
benchmark::RegisterBenchmark(Bench.name().c_str(),
45-
[=](benchmark::State& S) { Bench.run(S); });
43+
benchmark::RegisterBenchmark(Bench.name().c_str(), [=](benchmark::State& S) { Bench.run(S); });
4644
}
4745
}
4846
}
@@ -57,10 +55,8 @@ void makeBenchmarkImpl(const Args& A, std::tuple<U...> t) {
5755
makeBenchmarkFromValues<B<U...> >(A);
5856
}
5957

60-
template <template <class...> class B, class Args, class... U,
61-
class... T, class... Tuples>
62-
void makeBenchmarkImpl(const Args& A, std::tuple<U...>, std::tuple<T...>,
63-
Tuples... rest) {
58+
template <template <class...> class B, class Args, class... U, class... T, class... Tuples>
59+
void makeBenchmarkImpl(const Args& A, std::tuple<U...>, std::tuple<T...>, Tuples... rest) {
6460
(internal::makeBenchmarkImpl<B>(A, std::tuple<U..., T>(), rest...), ...);
6561
}
6662

@@ -70,15 +66,13 @@ void allValueCombinations(R& Result, const T& Final) {
7066
}
7167

7268
template <class R, class T, class V, class... Vs>
73-
void allValueCombinations(R& Result, const T& Prev, const V& Value,
74-
const Vs&... Values) {
69+
void allValueCombinations(R& Result, const T& Prev, const V& Value, const Vs&... Values) {
7570
for (const auto& E : Value) {
76-
allValueCombinations(Result, std::tuple_cat(Prev, std::make_tuple(E)),
77-
Values...);
71+
allValueCombinations(Result, std::tuple_cat(Prev, std::make_tuple(E)), Values...);
7872
}
7973
}
8074

81-
} // namespace internal
75+
} // namespace internal
8276

8377
// CRTP class that enables using enum types as a dimension for
8478
// makeCartesianProductBenchmark below.
@@ -93,8 +87,7 @@ void allValueCombinations(R& Result, const T& Prev, const V& Value,
9387
// };
9488
template <class Derived, class EnumType, size_t NumLabels>
9589
using EnumValuesAsTuple =
96-
decltype(internal::makeEnumValueTuple<Derived, EnumType>(
97-
std::make_index_sequence<NumLabels>{}));
90+
decltype(internal::makeEnumValueTuple<Derived, EnumType>(std::make_index_sequence<NumLabels>{}));
9891

9992
// Instantiates B<T0, T1, ..., TN> where <Ti...> are the combinations in the
10093
// cartesian product of `Tuples...`, and pass (arg0, ..., argN) as constructor
@@ -128,6 +121,7 @@ int makeCartesianProductBenchmark(const Args&... A) {
128121
// It returns `value`.
129122
template <class T>
130123
TEST_ALWAYS_INLINE inline T maybeOpaque(T value, bool opaque) {
131-
if (opaque) benchmark::DoNotOptimize(value);
124+
if (opaque)
125+
benchmark::DoNotOptimize(value);
132126
return value;
133127
}

Diff for: libcxx/benchmarks/ContainerBenchmarks.h

+74-76
Original file line numberDiff line numberDiff line change
@@ -59,116 +59,114 @@ void BM_ConstructSizeValue(benchmark::State& st, Container, typename Container::
5959

6060
template <class Container, class GenInputs>
6161
void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
62-
auto in = gen(st.range(0));
63-
const auto begin = in.begin();
64-
const auto end = in.end();
65-
benchmark::DoNotOptimize(&in);
66-
while (st.KeepRunning()) {
67-
Container c(begin, end);
68-
DoNotOptimizeData(c);
69-
}
62+
auto in = gen(st.range(0));
63+
const auto begin = in.begin();
64+
const auto end = in.end();
65+
benchmark::DoNotOptimize(&in);
66+
while (st.KeepRunning()) {
67+
Container c(begin, end);
68+
DoNotOptimizeData(c);
69+
}
7070
}
7171

7272
template <class Container, class GenInputs>
7373
void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
74-
auto in = gen(st.range(0));
75-
const auto end = in.end();
76-
while (st.KeepRunning()) {
77-
c.clear();
78-
for (auto it = in.begin(); it != end; ++it) {
79-
benchmark::DoNotOptimize(&(*c.insert(*it).first));
80-
}
81-
benchmark::ClobberMemory();
74+
auto in = gen(st.range(0));
75+
const auto end = in.end();
76+
while (st.KeepRunning()) {
77+
c.clear();
78+
for (auto it = in.begin(); it != end; ++it) {
79+
benchmark::DoNotOptimize(&(*c.insert(*it).first));
8280
}
81+
benchmark::ClobberMemory();
82+
}
8383
}
8484

8585
template <class Container, class GenInputs>
8686
void BM_InsertValueRehash(benchmark::State& st, Container c, GenInputs gen) {
87-
auto in = gen(st.range(0));
88-
const auto end = in.end();
89-
while (st.KeepRunning()) {
90-
c.clear();
91-
c.rehash(16);
92-
for (auto it = in.begin(); it != end; ++it) {
93-
benchmark::DoNotOptimize(&(*c.insert(*it).first));
94-
}
95-
benchmark::ClobberMemory();
87+
auto in = gen(st.range(0));
88+
const auto end = in.end();
89+
while (st.KeepRunning()) {
90+
c.clear();
91+
c.rehash(16);
92+
for (auto it = in.begin(); it != end; ++it) {
93+
benchmark::DoNotOptimize(&(*c.insert(*it).first));
9694
}
95+
benchmark::ClobberMemory();
96+
}
9797
}
9898

99-
10099
template <class Container, class GenInputs>
101100
void BM_InsertDuplicate(benchmark::State& st, Container c, GenInputs gen) {
102-
auto in = gen(st.range(0));
103-
const auto end = in.end();
104-
c.insert(in.begin(), in.end());
105-
benchmark::DoNotOptimize(&c);
106-
benchmark::DoNotOptimize(&in);
107-
while (st.KeepRunning()) {
108-
for (auto it = in.begin(); it != end; ++it) {
109-
benchmark::DoNotOptimize(&(*c.insert(*it).first));
110-
}
111-
benchmark::ClobberMemory();
101+
auto in = gen(st.range(0));
102+
const auto end = in.end();
103+
c.insert(in.begin(), in.end());
104+
benchmark::DoNotOptimize(&c);
105+
benchmark::DoNotOptimize(&in);
106+
while (st.KeepRunning()) {
107+
for (auto it = in.begin(); it != end; ++it) {
108+
benchmark::DoNotOptimize(&(*c.insert(*it).first));
112109
}
110+
benchmark::ClobberMemory();
111+
}
113112
}
114113

115-
116114
template <class Container, class GenInputs>
117115
void BM_EmplaceDuplicate(benchmark::State& st, Container c, GenInputs gen) {
118-
auto in = gen(st.range(0));
119-
const auto end = in.end();
120-
c.insert(in.begin(), in.end());
121-
benchmark::DoNotOptimize(&c);
122-
benchmark::DoNotOptimize(&in);
123-
while (st.KeepRunning()) {
124-
for (auto it = in.begin(); it != end; ++it) {
125-
benchmark::DoNotOptimize(&(*c.emplace(*it).first));
126-
}
127-
benchmark::ClobberMemory();
116+
auto in = gen(st.range(0));
117+
const auto end = in.end();
118+
c.insert(in.begin(), in.end());
119+
benchmark::DoNotOptimize(&c);
120+
benchmark::DoNotOptimize(&in);
121+
while (st.KeepRunning()) {
122+
for (auto it = in.begin(); it != end; ++it) {
123+
benchmark::DoNotOptimize(&(*c.emplace(*it).first));
128124
}
125+
benchmark::ClobberMemory();
126+
}
129127
}
130128

131129
template <class Container, class GenInputs>
132130
static void BM_Find(benchmark::State& st, Container c, GenInputs gen) {
133-
auto in = gen(st.range(0));
134-
c.insert(in.begin(), in.end());
135-
benchmark::DoNotOptimize(&(*c.begin()));
136-
const auto end = in.data() + in.size();
137-
while (st.KeepRunning()) {
138-
for (auto it = in.data(); it != end; ++it) {
139-
benchmark::DoNotOptimize(&(*c.find(*it)));
140-
}
141-
benchmark::ClobberMemory();
131+
auto in = gen(st.range(0));
132+
c.insert(in.begin(), in.end());
133+
benchmark::DoNotOptimize(&(*c.begin()));
134+
const auto end = in.data() + in.size();
135+
while (st.KeepRunning()) {
136+
for (auto it = in.data(); it != end; ++it) {
137+
benchmark::DoNotOptimize(&(*c.find(*it)));
142138
}
139+
benchmark::ClobberMemory();
140+
}
143141
}
144142

145143
template <class Container, class GenInputs>
146144
static void BM_FindRehash(benchmark::State& st, Container c, GenInputs gen) {
147-
c.rehash(8);
148-
auto in = gen(st.range(0));
149-
c.insert(in.begin(), in.end());
150-
benchmark::DoNotOptimize(&(*c.begin()));
151-
const auto end = in.data() + in.size();
152-
while (st.KeepRunning()) {
153-
for (auto it = in.data(); it != end; ++it) {
154-
benchmark::DoNotOptimize(&(*c.find(*it)));
155-
}
156-
benchmark::ClobberMemory();
145+
c.rehash(8);
146+
auto in = gen(st.range(0));
147+
c.insert(in.begin(), in.end());
148+
benchmark::DoNotOptimize(&(*c.begin()));
149+
const auto end = in.data() + in.size();
150+
while (st.KeepRunning()) {
151+
for (auto it = in.data(); it != end; ++it) {
152+
benchmark::DoNotOptimize(&(*c.find(*it)));
157153
}
154+
benchmark::ClobberMemory();
155+
}
158156
}
159157

160158
template <class Container, class GenInputs>
161159
static void BM_Rehash(benchmark::State& st, Container c, GenInputs gen) {
162-
auto in = gen(st.range(0));
163-
c.max_load_factor(3.0);
164-
c.insert(in.begin(), in.end());
165-
benchmark::DoNotOptimize(c);
166-
const auto bucket_count = c.bucket_count();
167-
while (st.KeepRunning()) {
168-
c.rehash(bucket_count + 1);
169-
c.rehash(bucket_count);
170-
benchmark::ClobberMemory();
171-
}
160+
auto in = gen(st.range(0));
161+
c.max_load_factor(3.0);
162+
c.insert(in.begin(), in.end());
163+
benchmark::DoNotOptimize(c);
164+
const auto bucket_count = c.bucket_count();
165+
while (st.KeepRunning()) {
166+
c.rehash(bucket_count + 1);
167+
c.rehash(bucket_count);
168+
benchmark::ClobberMemory();
169+
}
172170
}
173171

174172
} // end namespace ContainerBenchmarks

0 commit comments

Comments
 (0)