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

@@ -78,11 +78,15 @@ static void CopyUdp(uv::Stream& in, std::shared_ptr<uv::Udp> out,
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);
@@ -98,12 +102,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);
@@ -114,7 +121,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();
}
});
});
}
@@ -165,12 +174,20 @@ int main(int argc, char* argv[]) {
auto stderrTty = uv::Tty::Create(loop, 2, false);
// pass through our console to child's (bidirectional)
if (stdinTty) CopyStream(*stdinTty, stdinPipe);
if (stdoutTty) CopyStream(*stdoutPipe, stdoutTty);
if (stderrTty) CopyStream(*stderrPipe, stderrTty);
if (stdinTty) {
CopyStream(*stdinTty, stdinPipe);
}
if (stdoutTty) {
CopyStream(*stdoutPipe, stdoutTty);
}
if (stderrTty) {
CopyStream(*stderrPipe, stderrTty);
}
// when our stdin closes, also close child stdin
if (stdinTty) stdinTty->end.connect([stdinPipe] { stdinPipe->Close(); });
if (stdinTty) {
stdinTty->end.connect([stdinPipe] { stdinPipe->Close(); });
}
if (useUdp) {
auto udp = uv::Udp::Create(loop);
@@ -186,7 +203,9 @@ int main(int argc, char* argv[]) {
// when we get a connection, accept it
tcp->connection.connect([srv = tcp.get(), stdoutPipe, stderrPipe] {
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(); });
@@ -224,7 +243,9 @@ int main(int argc, char* argv[]) {
uv::Process::StdioCreatePipe(2, *stderrPipe, UV_WRITABLE_PIPE));
// pass our args as the child args (argv[1] becomes child argv[0], etc)
for (int i = programArgc; i < argc; ++i) options.emplace_back(argv[i]);
for (int i = programArgc; i < argc; ++i) {
options.emplace_back(argv[i]);
}
auto proc = uv::Process::SpawnArray(loop, argv[programArgc], options);
if (!proc) {
@@ -234,7 +255,9 @@ int main(int argc, char* argv[]) {
proc->exited.connect([](int64_t status, int) { std::exit(status); });
// start reading
if (stdinTty) stdinTty->StartRead();
if (stdinTty) {
stdinTty->StartRead();
}
stdoutPipe->StartRead();
stderrPipe->StartRead();