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

@@ -60,15 +60,23 @@ void HttpServerConnection::BuildHeader(raw_ostream& os, int code,
const Twine& extra) {
os << "HTTP/" << m_request.GetMajor() << '.' << m_request.GetMinor() << ' '
<< code << ' ' << codeText << "\r\n";
if (contentLength == 0) m_keepAlive = false;
if (!m_keepAlive) os << "Connection: close\r\n";
if (contentLength == 0) {
m_keepAlive = false;
}
if (!m_keepAlive) {
os << "Connection: close\r\n";
}
BuildCommonHeaders(os);
os << "Content-Type: " << contentType << "\r\n";
if (contentLength != 0) os << "Content-Length: " << contentLength << "\r\n";
if (contentLength != 0) {
os << "Content-Length: " << contentLength << "\r\n";
}
os << "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: *\r\n";
SmallString<128> extraBuf;
StringRef extraStr = extra.toStringRef(extraBuf);
if (!extraStr.empty()) os << extraStr;
if (!extraStr.empty()) {
os << extraStr;
}
os << "\r\n"; // header ends with a blank line
}
@@ -76,8 +84,12 @@ void HttpServerConnection::SendData(ArrayRef<uv::Buffer> bufs,
bool closeAfter) {
m_stream.Write(bufs, [closeAfter, stream = &m_stream](
MutableArrayRef<uv::Buffer> bufs, uv::Error) {
for (auto&& buf : bufs) buf.Deallocate();
if (closeAfter) stream->Close();
for (auto&& buf : bufs) {
buf.Deallocate();
}
if (closeAfter) {
stream->Close();
}
});
}
@@ -100,8 +112,9 @@ void HttpServerConnection::SendStaticResponse(int code, const Twine& codeText,
// TODO: handle remote side not accepting gzip (very rare)
StringRef contentEncodingHeader;
if (gzipped /* && m_acceptGzip*/)
if (gzipped /* && m_acceptGzip*/) {
contentEncodingHeader = "Content-Encoding: gzip\r\n";
}
SmallVector<uv::Buffer, 4> bufs;
raw_uv_ostream os{bufs, 4096};
@@ -113,8 +126,12 @@ void HttpServerConnection::SendStaticResponse(int code, const Twine& codeText,
m_stream.Write(bufs, [closeAfter = !m_keepAlive, stream = &m_stream](
MutableArrayRef<uv::Buffer> bufs, uv::Error) {
// don't deallocate the static content
for (auto&& buf : bufs.drop_back()) buf.Deallocate();
if (closeAfter) stream->Close();
for (auto&& buf : bufs.drop_back()) {
buf.Deallocate();
}
if (closeAfter) {
stream->Close();
}
});
}