mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -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]))) {
|
||||
|
||||
Reference in New Issue
Block a user