Skip to content

Commit 2f53a56

Browse files
authored
CXX-3198 modernize ClangFormat configuration options (#1306)
* format: set ColumnLimit: 120 * format: set AlignAfterOpenBracket: AlwaysBreak * format: set AllowAllParametersOfDeclarationOnNextLine: false * format: set QualifierAlignment: Right * format: set SpacesBeforeTrailingComments: 1 * format: set ShortNamespaceLines: 0 * format: set KeepEmptyLines.AtStartOfFile: false * Address GCC -fpermissive error due to `view` declaration conflict * Manually fix qualifier alignments missed by ClangFormat
1 parent 91b9d75 commit 2f53a56

File tree

790 files changed

+9392
-10964
lines changed

Some content is hidden

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

790 files changed

+9392
-10964
lines changed

Diff for: .clang-format

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
Language: Cpp
33
AccessModifierOffset: -1
4-
AlignAfterOpenBracket: Align
4+
AlignAfterOpenBracket: AlwaysBreak
55
AlignArrayOfStructures: None
66
AlignConsecutiveAssignments:
77
Enabled: false
@@ -64,7 +64,7 @@ AlignTrailingComments:
6464
Kind: Always
6565
OverEmptyLines: 0
6666
AllowAllArgumentsOnNextLine: true
67-
AllowAllParametersOfDeclarationOnNextLine: true
67+
AllowAllParametersOfDeclarationOnNextLine: false
6868
AllowBreakBeforeNoexceptSpecifier: Never
6969
AllowShortBlocksOnASingleLine: Never
7070
AllowShortCaseExpressionOnASingleLine: true
@@ -126,7 +126,7 @@ BreakFunctionDefinitionParameters: false
126126
BreakInheritanceList: BeforeColon
127127
BreakStringLiterals: true
128128
BreakTemplateDeclarations: Yes
129-
ColumnLimit: 100
129+
ColumnLimit: 120
130130
CommentPragmas: '^\s*(@(addtogroup|copydoc|defgroup|fn|ref)|- )'
131131
CompactNamespaces: false
132132
ConstructorInitializerIndentWidth: 4
@@ -190,7 +190,7 @@ JavaScriptWrapImports: true
190190
KeepEmptyLines:
191191
AtEndOfFile: false
192192
AtStartOfBlock: false
193-
AtStartOfFile: true
193+
AtStartOfFile: false
194194
LambdaBodyIndentation: Signature
195195
LineEnding: DeriveLF
196196
MacroBlockBegin: ''
@@ -217,7 +217,7 @@ PenaltyIndentedWhitespace: 0
217217
PenaltyReturnTypeOnItsOwnLine: 200
218218
PointerAlignment: Left
219219
PPIndentWidth: -1
220-
QualifierAlignment: Left
220+
QualifierAlignment: Right
221221
RawStringFormats: []
222222
ReferenceAlignment: Pointer
223223
ReflowComments: true
@@ -227,7 +227,7 @@ RemoveSemicolon: false
227227
RequiresClausePosition: OwnLine
228228
RequiresExpressionIndentation: OuterScope
229229
SeparateDefinitionBlocks: Leave
230-
ShortNamespaceLines: 1
230+
ShortNamespaceLines: 0
231231
SkipMacroDefinitionBody: false
232232
SortIncludes: CaseSensitive
233233
SortJavaStaticImport: Before
@@ -257,7 +257,7 @@ SpaceBeforeParensOptions:
257257
SpaceBeforeRangeBasedForLoopColon: true
258258
SpaceBeforeSquareBrackets: false
259259
SpaceInEmptyBlock: false
260-
SpacesBeforeTrailingComments: 2
260+
SpacesBeforeTrailingComments: 1
261261
SpacesInAngles: Never
262262
SpacesInContainerLiterals: true
263263
SpacesInLineCommentPrefix:

Diff for: benchmark/benchmark_runner.cpp

+18-29
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,25 @@ namespace benchmark {
4747
// The task sizes and iteration numbers come from the Driver Perfomance Benchmarking Reference Doc.
4848
benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{types} {
4949
// Bson microbenchmarks
50-
_microbenches.push_back(
51-
std::make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
52-
_microbenches.push_back(
53-
std::make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
54-
_microbenches.push_back(
55-
std::make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
50+
_microbenches.push_back(std::make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
51+
_microbenches.push_back(std::make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
52+
_microbenches.push_back(std::make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
5653
// TODO CXX-1241: Add bson_decoding equivalents.
5754

5855
// Single doc microbenchmarks
5956
_microbenches.push_back(std::make_unique<run_command>());
60-
_microbenches.push_back(
61-
std::make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
57+
_microbenches.push_back(std::make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
6258
_microbenches.push_back(std::make_unique<insert_one>(
6359
"TestSmallDocInsertOne", 2.75, iterations, "single_and_multi_document/small_doc.json"));
64-
_microbenches.push_back(std::make_unique<insert_one>(
65-
"TestLargeDocInsertOne", 27.31, 10, "single_and_multi_document/large_doc.json"));
60+
_microbenches.push_back(
61+
std::make_unique<insert_one>("TestLargeDocInsertOne", 27.31, 10, "single_and_multi_document/large_doc.json"));
6662

6763
// Multi doc microbenchmarks
6864
_microbenches.push_back(std::make_unique<find_many>("single_and_multi_document/tweet.json"));
6965
_microbenches.push_back(std::make_unique<bulk_insert>(
7066
"TestSmallDocBulkInsert", 2.75, iterations, "single_and_multi_document/small_doc.json"));
71-
_microbenches.push_back(std::make_unique<bulk_insert>(
72-
"TestLargeDocBulkInsert", 27.31, 10, "single_and_multi_document/large_doc.json"));
67+
_microbenches.push_back(
68+
std::make_unique<bulk_insert>("TestLargeDocBulkInsert", 27.31, 10, "single_and_multi_document/large_doc.json"));
7369
// CXX-2794: Disable GridFS benchmarks due to long runtime
7470
// _microbenches.push_back(
7571
// std::make_unique<gridfs_upload>("single_and_multi_document/gridfs_large.bin"));
@@ -86,13 +82,10 @@ benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{type
8682
// Need to remove some
8783
if (!_types.empty()) {
8884
for (auto&& it = _microbenches.begin(); it != _microbenches.end();) {
89-
const std::set<benchmark_type>& tags = (*it)->get_tags();
85+
std::set<benchmark_type> const& tags = (*it)->get_tags();
9086
std::set<benchmark_type> intersect;
91-
std::set_intersection(tags.begin(),
92-
tags.end(),
93-
_types.begin(),
94-
_types.end(),
95-
std::inserter(intersect, intersect.begin()));
87+
std::set_intersection(
88+
tags.begin(), tags.end(), _types.begin(), _types.end(), std::inserter(intersect, intersect.begin()));
9689

9790
if (intersect.empty()) {
9891
_microbenches.erase(it);
@@ -112,8 +105,7 @@ void benchmark_runner::run_microbenches() {
112105

113106
auto score = bench->get_results();
114107

115-
std::cout << bench->get_name() << ": "
116-
<< static_cast<double>(score.get_percentile(50).count()) / 1000.0
108+
std::cout << bench->get_name() << ": " << static_cast<double>(score.get_percentile(50).count()) / 1000.0
117109
<< " second(s) | " << score.get_score() << " MB/s" << std::endl
118110
<< std::endl;
119111
}
@@ -168,12 +160,9 @@ void benchmark_runner::write_scores() {
168160
using builder::basic::sub_document;
169161

170162
auto doc = builder::basic::document{};
171-
doc.append(kvp("info", [](sub_document subdoc) {
172-
subdoc.append(kvp("test_name", "C++ Driver microbenchmarks"));
173-
}));
163+
doc.append(kvp("info", [](sub_document subdoc) { subdoc.append(kvp("test_name", "C++ Driver microbenchmarks")); }));
174164

175-
auto write_time =
176-
[](const std::chrono::time_point<std::chrono::system_clock> t) -> std::string {
165+
auto write_time = [](std::chrono::time_point<std::chrono::system_clock> const t) -> std::string {
177166
std::time_t t1 = std::chrono::system_clock::to_time_t(t);
178167
std::ostringstream oss;
179168
oss << std::put_time(std::gmtime(&t1), "%Y-%m-%dT%H:%M:%S") << "+00:00";
@@ -189,10 +178,10 @@ void benchmark_runner::write_scores() {
189178
std::cout << "Individual microbenchmark scores:" << std::endl << "===========" << std::endl;
190179
for (auto&& bench : _microbenches) {
191180
auto& score = bench->get_results();
192-
const auto bench_time = static_cast<double>(score.get_percentile(50).count()) / 1000.0;
181+
auto const bench_time = static_cast<double>(score.get_percentile(50).count()) / 1000.0;
193182

194-
std::cout << bench->get_name() << ": " << bench_time << " seconds | " << score.get_score()
195-
<< " MB/s" << std::endl;
183+
std::cout << bench->get_name() << ": " << bench_time << " seconds | " << score.get_score() << " MB/s"
184+
<< std::endl;
196185

197186
auto metric_doc = builder::basic::document{};
198187
metric_doc.append(kvp("name", bench->get_name()));
@@ -232,4 +221,4 @@ void benchmark_runner::write_scores() {
232221
std::ofstream os{"results.json"};
233222
os << '[' << bsoncxx::to_json(doc.view()) << ']';
234223
}
235-
} // namespace benchmark
224+
} // namespace benchmark

Diff for: benchmark/benchmark_runner.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ class benchmark_runner {
5454
std::vector<std::unique_ptr<microbench>> _microbenches;
5555
std::set<benchmark_type> _types;
5656
};
57-
} // namespace benchmark
57+
} // namespace benchmark

Diff for: benchmark/bson/bson_decoding.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class bson_decoding : public microbench {
2323
bson_decoding() = delete;
2424

2525
bson_decoding(std::string name, double task_size, std::string json_file)
26-
: microbench{std::move(name),
27-
task_size,
28-
std::set<benchmark_type>{benchmark_type::bson_bench}},
26+
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::bson_bench}},
2927
_file_name{std::move(json_file)} {}
3028

3129
protected:
@@ -46,4 +44,4 @@ void bson_decoding::task() {
4644
// TODO CXX-1241: call bson_as_extended json on _json.
4745
}
4846
}
49-
} // namespace benchmark
47+
} // namespace benchmark

Diff for: benchmark/bson/bson_encoding.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class bson_encoding : public microbench {
2828
bson_encoding() = delete;
2929

3030
bson_encoding(std::string name, double task_size, std::string json_file)
31-
: microbench{std::move(name),
32-
task_size,
33-
std::set<benchmark_type>{benchmark_type::bson_bench}},
31+
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::bson_bench}},
3432
_json_file{std::move(json_file)} {}
3533

3634
protected:
@@ -64,4 +62,4 @@ void bson_encoding::task() {
6462
}
6563

6664
void bson_encoding::teardown() {}
67-
} // namespace benchmark
65+
} // namespace benchmark

Diff for: benchmark/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main(int argc, char* argv[]) {
3232

3333
if (argc > 1) {
3434
if (bsoncxx::stdx::string_view(argv[1]) == "all") {
35-
for (const auto& [name, type] : names_types) {
35+
for (auto const& [name, type] : names_types) {
3636
types.insert(type);
3737
}
3838
} else {

Diff for: benchmark/microbench.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
namespace benchmark {
2323

24-
bool finished_running(const std::chrono::duration<std::uint32_t, std::milli>& curr_time,
25-
std::uint32_t iter) {
24+
bool finished_running(std::chrono::duration<std::uint32_t, std::milli> const& curr_time, std::uint32_t iter) {
2625
return (curr_time > maxtime || (curr_time > mintime && iter > max_iter));
2726
}
2827

@@ -44,7 +43,7 @@ void microbench::run() {
4443
teardown();
4544
}
4645

47-
std::vector<std::string> parse_json_file_to_strings(const std::string& json_file) {
46+
std::vector<std::string> parse_json_file_to_strings(std::string const& json_file) {
4847
std::vector<std::string> jsons;
4948
std::ifstream stream{"data/benchmark/" + json_file};
5049

@@ -60,7 +59,7 @@ std::vector<std::string> parse_json_file_to_strings(const std::string& json_file
6059
return jsons;
6160
}
6261

63-
std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::string& json_file) {
62+
std::vector<bsoncxx::document::value> parse_json_file_to_documents(std::string const& json_file) {
6463
std::vector<bsoncxx::document::value> docs;
6564
std::ifstream stream{"data/benchmark/" + json_file};
6665

@@ -79,12 +78,11 @@ std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::st
7978
return docs;
8079
}
8180

82-
std::vector<std::string> parse_documents_to_bson(
83-
const std::vector<bsoncxx::document::value>& docs) {
81+
std::vector<std::string> parse_documents_to_bson(std::vector<bsoncxx::document::value> const& docs) {
8482
std::vector<std::string> bsons;
8583
for (std::uint32_t i = 0; i < docs.size(); i++) {
8684
bsons.push_back(bsoncxx::to_json(docs[i]));
8785
}
8886
return bsons;
8987
}
90-
} // namespace benchmark
88+
} // namespace benchmark

Diff for: benchmark/microbench.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum class benchmark_type {
3737
run_command_bench,
3838
};
3939

40-
static const std::unordered_map<benchmark_type, std::string> type_names = {
40+
static std::unordered_map<benchmark_type, std::string> const type_names = {
4141
{benchmark_type::bson_bench, "BSONBench"},
4242
{benchmark_type::single_bench, "SingleBench"},
4343
{benchmark_type::multi_bench, "MultiBench"},
@@ -46,7 +46,7 @@ static const std::unordered_map<benchmark_type, std::string> type_names = {
4646
{benchmark_type::write_bench, "WriteBench"},
4747
{benchmark_type::run_command_bench, "RunCommandBench"}};
4848

49-
static const std::unordered_map<std::string, benchmark_type> names_types = {
49+
static std::unordered_map<std::string, benchmark_type> const names_types = {
5050
{"BSONBench", benchmark_type::bson_bench},
5151
{"SingleBench", benchmark_type::single_bench},
5252
{"MultiBench", benchmark_type::multi_bench},
@@ -72,8 +72,8 @@ class microbench {
7272

7373
microbench(microbench&&) = default;
7474
microbench& operator=(microbench&&) = default;
75-
microbench(const microbench&) = default;
76-
microbench& operator=(const microbench&) = default;
75+
microbench(microbench const&) = default;
76+
microbench& operator=(microbench const&) = default;
7777

7878
void run();
7979

@@ -85,7 +85,7 @@ class microbench {
8585
return _score;
8686
}
8787

88-
const std::set<benchmark_type>& get_tags() {
88+
std::set<benchmark_type> const& get_tags() {
8989
return _tags;
9090
}
9191

@@ -109,9 +109,9 @@ class microbench {
109109
std::string _name;
110110
};
111111

112-
std::vector<std::string> parse_json_file_to_strings(const std::string& json_file);
112+
std::vector<std::string> parse_json_file_to_strings(std::string const& json_file);
113113

114-
std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::string& json_file);
114+
std::vector<bsoncxx::document::value> parse_json_file_to_documents(std::string const& json_file);
115115

116-
std::vector<std::string> parse_documents_to_bson(const std::vector<bsoncxx::document::value>& docs);
117-
} // namespace benchmark
116+
std::vector<std::string> parse_documents_to_bson(std::vector<bsoncxx::document::value> const& docs);
117+
} // namespace benchmark

Diff for: benchmark/multi_doc/bulk_insert.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class bulk_insert : public microbench {
3636
bulk_insert() = delete;
3737

3838
bulk_insert(std::string name, double task_size, std::int32_t doc_num, std::string json_file)
39-
: microbench{std::move(name),
40-
task_size,
41-
std::set<benchmark_type>{benchmark_type::multi_bench,
42-
benchmark_type::write_bench}},
39+
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::write_bench}},
4340
_conn{mongocxx::uri{}},
4441
_doc_num{doc_num},
4542
_file_name{std::move(json_file)} {}
@@ -85,4 +82,4 @@ void bulk_insert::teardown() {
8582
void bulk_insert::task() {
8683
_coll.insert_many(_docs);
8784
}
88-
} // namespace benchmark
85+
} // namespace benchmark

Diff for: benchmark/multi_doc/find_many.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ class find_many : public microbench {
3333
public:
3434
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
3535
find_many(std::string json_file)
36-
: microbench{"TestFindManyAndEmptyCursor",
37-
16.22,
38-
std::set<benchmark_type>{benchmark_type::multi_bench,
39-
benchmark_type::read_bench}},
36+
: microbench{"TestFindManyAndEmptyCursor", 16.22, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::read_bench}},
4037
_conn{mongocxx::uri{}},
4138
_json_file{std::move(json_file)} {}
4239

@@ -74,4 +71,4 @@ void find_many::task() {
7471
for ([[maybe_unused]] auto&& doc : cursor) {
7572
}
7673
}
77-
} // namespace benchmark
74+
} // namespace benchmark

Diff for: benchmark/multi_doc/gridfs_download.hpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class gridfs_download : public microbench {
3636
public:
3737
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
3838
gridfs_download(std::string file_name)
39-
: microbench{"TestGridFsDownload",
40-
52.43,
41-
std::set<benchmark_type>{benchmark_type::multi_bench,
42-
benchmark_type::read_bench}},
39+
: microbench{"TestGridFsDownload", 52.43, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::read_bench}},
4340
_conn{mongocxx::uri{}},
4441
_file_name{std::move(file_name)} {}
4542

@@ -77,8 +74,7 @@ void gridfs_download::task() {
7774
auto buffer_size = std::min(file_length, static_cast<std::int64_t>(downloader.chunk_size()));
7875
auto buffer = std::make_unique<std::uint8_t[]>(static_cast<std::size_t>(buffer_size));
7976

80-
while ([[maybe_unused]] auto length_read =
81-
downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size))) {
77+
while ([[maybe_unused]] auto length_read = downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size))) {
8278
}
8379
}
84-
} // namespace benchmark
80+
} // namespace benchmark

Diff for: benchmark/multi_doc/gridfs_upload.hpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ class gridfs_upload : public microbench {
3434
public:
3535
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
3636
gridfs_upload(std::string file_name)
37-
: microbench{"TestGridFsUpload",
38-
52.43,
39-
std::set<benchmark_type>{benchmark_type::multi_bench,
40-
benchmark_type::write_bench}},
37+
: microbench{"TestGridFsUpload", 52.43, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::write_bench}},
4138
_conn{mongocxx::uri{}},
4239
_file_name{file_name} {}
4340

@@ -60,8 +57,8 @@ class gridfs_upload : public microbench {
6057
void gridfs_upload::setup() {
6158
std::ifstream stream{_file_name};
6259
stream >> std::noskipws;
63-
_gridfs_file = std::vector<std::uint8_t>{(std::istream_iterator<unsigned char>{stream}),
64-
(std::istream_iterator<unsigned char>{})};
60+
_gridfs_file = std::vector<std::uint8_t>{
61+
(std::istream_iterator<unsigned char>{stream}), (std::istream_iterator<unsigned char>{})};
6562

6663
mongocxx::database db = _conn["perftest"];
6764
db.drop();
@@ -87,4 +84,4 @@ void gridfs_upload::task() {
8784
uploader.write(_gridfs_file.data(), _gridfs_file.size());
8885
uploader.close();
8986
}
90-
} // namespace benchmark
87+
} // namespace benchmark

0 commit comments

Comments
 (0)