AK: Avoid else after return in files commonly included by the Kernel

This commit is contained in:
Andrew Kaster 2021-11-06 11:24:53 -06:00 committed by Andreas Kling
parent 07f4e91b94
commit e982253c33
Notes: sideshowbarker 2024-07-18 01:08:19 +09:00
3 changed files with 28 additions and 38 deletions

View file

@ -51,8 +51,7 @@ template<typename T>
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange_n(var, &expected, desired, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange_n(var, &expected, desired, false, order, order);
return __atomic_compare_exchange_n(var, &expected, desired, false, order, order);
}
template<typename T, typename V = RemoveVolatile<T>>
@ -60,8 +59,7 @@ template<typename T, typename V = RemoveVolatile<T>>
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange_n(var, &expected, desired, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange_n(var, &expected, desired, false, order, order);
return __atomic_compare_exchange_n(var, &expected, desired, false, order, order);
}
template<typename T, typename V = RemoveVolatile<T>>
@ -69,8 +67,7 @@ template<typename T, typename V = RemoveVolatile<T>>
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange_n(const_cast<V**>(var), &expected, nullptr, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange_n(const_cast<V**>(var), &expected, nullptr, false, order, order);
return __atomic_compare_exchange_n(const_cast<V**>(var), &expected, nullptr, false, order, order);
}
template<typename T>
@ -174,8 +171,7 @@ public:
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange(&m_value, &expected, &desired, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange(&m_value, &expected, &desired, false, order, order);
return __atomic_compare_exchange(&m_value, &expected, &desired, false, order, order);
}
ALWAYS_INLINE operator T() const volatile noexcept
@ -238,8 +234,7 @@ public:
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, order, order);
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, order, order);
}
ALWAYS_INLINE T operator++() volatile noexcept
@ -369,8 +364,7 @@ public:
{
if (order == memory_order_acq_rel || order == memory_order_release)
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, memory_order_release, memory_order_acquire);
else
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, order, order);
return __atomic_compare_exchange_n(&m_value, &expected, desired, false, order, order);
}
T* operator++() volatile noexcept

View file

@ -118,9 +118,9 @@ protected:
{
Node* candidate = nullptr;
while (node) {
if (key == node->key) {
if (key == node->key)
return node;
} else if (key < node->key) {
if (key < node->key) {
node = node->left_child;
} else {
candidate = node;
@ -137,11 +137,10 @@ protected:
Node* temp = m_root;
while (temp) {
parent = temp;
if (node->key < temp->key) {
if (node->key < temp->key)
temp = temp->left_child;
} else {
else
temp = temp->right_child;
}
}
if (!parent) { // new root
node->color = Color::Black;
@ -149,11 +148,11 @@ protected:
m_size = 1;
m_minimum = node;
return;
} else if (node->key < parent->key) { // we are the left child
parent->left_child = node;
} else { // we are the right child
parent->right_child = node;
}
if (node->key < parent->key) // we are the left child
parent->left_child = node;
else // we are the right child
parent->right_child = node;
node->parent = parent;
if (node->parent->parent) // no fixups to be done for a height <= 2 tree
@ -351,14 +350,13 @@ protected:
while (node->left_child)
node = node->left_child;
return node;
} else {
auto temp = node->parent;
while (temp && node == temp->right_child) {
node = temp;
temp = temp->parent;
}
return temp;
}
auto temp = node->parent;
while (temp && node == temp->right_child) {
node = temp;
temp = temp->parent;
}
return temp;
}
static Node* predecessor(Node* node)
@ -369,14 +367,13 @@ protected:
while (node->right_child)
node = node->right_child;
return node;
} else {
auto temp = node->parent;
while (temp && node == temp->left_child) {
node = temp;
temp = temp->parent;
}
return temp;
}
auto temp = node->parent;
while (temp && node == temp->left_child) {
node = temp;
temp = temp->parent;
}
return temp;
}
Node* m_root { nullptr };

View file

@ -141,9 +141,8 @@ constexpr bool is_constant_evaluated()
constexpr type abs(type num) \
{ \
if (is_constant_evaluated()) \
return num < zero ? -num : num; \
else \
return __builtin_##intrinsic(num); \
return num < (zero) ? -num : num; \
return __builtin_##intrinsic(num); \
}
__DEFINE_GENERIC_ABS(int, 0, abs);