Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -69,11 +69,15 @@ static void CopyUdp(uv::Stream& in, std::shared_ptr<uv::Udp> out, int port,
uv::Buffer& buf, size_t len) {
// build buffers
wpi::SmallVector<uv::Buffer, 4> bufs;
if (!NewlineBuffer(*rem, buf, len, bufs, false, 0)) return;
if (!NewlineBuffer(*rem, buf, len, bufs, false, 0)) {
return;
}
// send output
outPtr->Send(addr, bufs, [](auto bufs2, uv::Error) {
for (auto buf : bufs2) buf.Deallocate();
for (auto buf : bufs2) {
buf.Deallocate();
}
});
},
out);
@@ -89,12 +93,15 @@ static void CopyTcp(uv::Stream& in, std::shared_ptr<uv::Stream> out) {
uv::Buffer& buf, size_t len) {
// build buffers
wpi::SmallVector<uv::Buffer, 4> bufs;
if (!NewlineBuffer(data->rem, buf, len, bufs, true, data->seq++))
if (!NewlineBuffer(data->rem, buf, len, bufs, true, data->seq++)) {
return;
}
// send output
outPtr->Write(bufs, [](auto bufs2, uv::Error) {
for (auto buf : bufs2) buf.Deallocate();
for (auto buf : bufs2) {
buf.Deallocate();
}
});
},
out);
@@ -105,7 +112,9 @@ static void CopyStream(uv::Stream& in, std::shared_ptr<uv::Stream> out) {
uv::Buffer buf2 = buf.Dup();
buf2.len = len;
out->Write(buf2, [](auto bufs, uv::Error) {
for (auto buf : bufs) buf.Deallocate();
for (auto buf : bufs) {
buf.Deallocate();
}
});
});
}
@@ -156,10 +165,14 @@ int main(int argc, char* argv[]) {
auto stdoutTty = uv::Tty::Create(loop, 1, false);
// don't bother continuing if we don't have a stdin
if (!stdinTty) return EXIT_SUCCESS;
if (!stdinTty) {
return EXIT_SUCCESS;
}
// pass through our input to output
if (stdoutTty) CopyStream(*stdinTty, stdoutTty);
if (stdoutTty) {
CopyStream(*stdinTty, stdoutTty);
}
// when our stdin closes, exit
stdinTty->end.connect([] { std::exit(EXIT_SUCCESS); });
@@ -177,7 +190,9 @@ int main(int argc, char* argv[]) {
// when we get a connection, accept it
tcp->connection.connect([srv = tcp.get(), stdinTty] {
auto tcp = srv->Accept();
if (!tcp) return;
if (!tcp) {
return;
}
// close on error
tcp->error.connect([s = tcp.get()](wpi::uv::Error err) { s->Close(); });
@@ -191,7 +206,9 @@ int main(int argc, char* argv[]) {
}
// start reading
if (stdinTty) stdinTty->StartRead();
if (stdinTty) {
stdinTty->StartRead();
}
// run the loop!
loop->Run();