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

@@ -25,18 +25,26 @@ InstanceImpl::InstanceImpl(int inst)
logger.set_min_level(logger_impl.GetMinLevel());
}
InstanceImpl::~InstanceImpl() { logger.SetLogger(nullptr); }
InstanceImpl::~InstanceImpl() {
logger.SetLogger(nullptr);
}
InstanceImpl* InstanceImpl::GetDefault() { return Get(GetDefaultIndex()); }
InstanceImpl* InstanceImpl::GetDefault() {
return Get(GetDefaultIndex());
}
InstanceImpl* InstanceImpl::Get(int inst) {
if (inst < 0) return nullptr;
if (inst < 0) {
return nullptr;
}
// fast path, just an atomic read
if (static_cast<unsigned int>(inst) <
(sizeof(s_fast_instances) / sizeof(s_fast_instances[0]))) {
InstanceImpl* ptr = s_fast_instances[inst];
if (ptr) return ptr;
if (ptr) {
return ptr;
}
}
// slow path
@@ -60,14 +68,18 @@ InstanceImpl* InstanceImpl::Get(int inst) {
int InstanceImpl::GetDefaultIndex() {
int inst = s_default;
if (inst >= 0) return inst;
if (inst >= 0) {
return inst;
}
// slow path
std::scoped_lock lock(s_mutex);
// double-check
inst = s_default;
if (inst >= 0) return inst;
if (inst >= 0) {
return inst;
}
// alloc and save
inst = AllocImpl();
@@ -94,7 +106,9 @@ int InstanceImpl::AllocImpl() {
void InstanceImpl::Destroy(int inst) {
std::scoped_lock lock(s_mutex);
if (inst < 0 || static_cast<unsigned int>(inst) >= s_instances.size()) return;
if (inst < 0 || static_cast<unsigned int>(inst) >= s_instances.size()) {
return;
}
if (static_cast<unsigned int>(inst) <
(sizeof(s_fast_instances) / sizeof(s_fast_instances[0]))) {