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

@@ -14,7 +14,9 @@ using namespace cs;
int PropertyContainer::GetPropertyIndex(const wpi::Twine& name) const {
// We can't fail, so instead we create a new index if caching fails.
CS_Status status = 0;
if (!m_properties_cached) CacheProperties(&status);
if (!m_properties_cached) {
CacheProperties(&status);
}
std::scoped_lock lock(m_mutex);
wpi::SmallVector<char, 64> nameBuf;
int& ndx = m_properties[name.toStringRef(nameBuf)];
@@ -28,39 +30,50 @@ int PropertyContainer::GetPropertyIndex(const wpi::Twine& name) const {
wpi::ArrayRef<int> PropertyContainer::EnumerateProperties(
wpi::SmallVectorImpl<int>& vec, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return wpi::ArrayRef<int>{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
for (int i = 0; i < static_cast<int>(m_propertyData.size()); ++i) {
if (m_propertyData[i]) vec.push_back(i + 1);
if (m_propertyData[i]) {
vec.push_back(i + 1);
}
}
return vec;
}
CS_PropertyKind PropertyContainer::GetPropertyKind(int property) const {
CS_Status status = 0;
if (!m_properties_cached && !CacheProperties(&status)) return CS_PROP_NONE;
if (!m_properties_cached && !CacheProperties(&status)) {
return CS_PROP_NONE;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) return CS_PROP_NONE;
if (!prop) {
return CS_PROP_NONE;
}
return prop->propKind;
}
wpi::StringRef PropertyContainer::GetPropertyName(
int property, wpi::SmallVectorImpl<char>& buf, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return wpi::StringRef{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
return wpi::StringRef{};
return {};
}
// safe to not copy because we never modify it after caching
return prop->name;
}
int PropertyContainer::GetProperty(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
if (!m_properties_cached && !CacheProperties(status)) {
return 0;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
@@ -85,7 +98,9 @@ void PropertyContainer::SetProperty(int property, int value,
}
// Guess it's integer if we've set before get
if (prop->propKind == CS_PROP_NONE) prop->propKind = CS_PROP_INTEGER;
if (prop->propKind == CS_PROP_NONE) {
prop->propKind = CS_PROP_INTEGER;
}
if ((prop->propKind & (CS_PROP_BOOLEAN | CS_PROP_INTEGER | CS_PROP_ENUM)) ==
0) {
@@ -97,7 +112,9 @@ void PropertyContainer::SetProperty(int property, int value,
}
int PropertyContainer::GetPropertyMin(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
if (!m_properties_cached && !CacheProperties(status)) {
return 0;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
@@ -108,7 +125,9 @@ int PropertyContainer::GetPropertyMin(int property, CS_Status* status) const {
}
int PropertyContainer::GetPropertyMax(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
if (!m_properties_cached && !CacheProperties(status)) {
return 0;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
@@ -119,7 +138,9 @@ int PropertyContainer::GetPropertyMax(int property, CS_Status* status) const {
}
int PropertyContainer::GetPropertyStep(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
if (!m_properties_cached && !CacheProperties(status)) {
return 0;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
@@ -131,7 +152,9 @@ int PropertyContainer::GetPropertyStep(int property, CS_Status* status) const {
int PropertyContainer::GetPropertyDefault(int property,
CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
if (!m_properties_cached && !CacheProperties(status)) {
return 0;
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
@@ -143,16 +166,18 @@ int PropertyContainer::GetPropertyDefault(int property,
wpi::StringRef PropertyContainer::GetStringProperty(
int property, wpi::SmallVectorImpl<char>& buf, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return wpi::StringRef{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
return wpi::StringRef{};
return {};
}
if (prop->propKind != CS_PROP_STRING) {
*status = CS_WRONG_PROPERTY_TYPE;
return wpi::StringRef{};
return {};
}
buf.clear();
buf.append(prop->valueStr.begin(), prop->valueStr.end());
@@ -169,7 +194,9 @@ void PropertyContainer::SetStringProperty(int property, const wpi::Twine& value,
}
// Guess it's string if we've set before get
if (prop->propKind == CS_PROP_NONE) prop->propKind = CS_PROP_STRING;
if (prop->propKind == CS_PROP_NONE) {
prop->propKind = CS_PROP_STRING;
}
if (prop->propKind != CS_PROP_STRING) {
*status = CS_WRONG_PROPERTY_TYPE;
@@ -181,17 +208,18 @@ void PropertyContainer::SetStringProperty(int property, const wpi::Twine& value,
std::vector<std::string> PropertyContainer::GetEnumPropertyChoices(
int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return std::vector<std::string>{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
return std::vector<std::string>{};
return {};
}
if (prop->propKind != CS_PROP_ENUM) {
*status = CS_WRONG_PROPERTY_TYPE;
return std::vector<std::string>{};
return {};
}
return prop->enumChoices;
}