AK: Resolve clang-tidy readability-bool-conversion warnings

... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
This commit is contained in:
Andrew Kaster 2021-11-06 14:12:16 -06:00 committed by Andreas Kling
parent 10d0cac73c
commit 22feb9d47b
Notes: sideshowbarker 2024-07-18 01:08:10 +09:00
12 changed files with 26 additions and 25 deletions

View File

@ -91,7 +91,7 @@ public:
if (previous_data != nullptr) { if (previous_data != nullptr) {
__builtin_memcpy(m_data, previous_data, previous_size_bytes); __builtin_memcpy(m_data, previous_data, previous_size_bytes);
if (previous_size % 8) if ((previous_size % 8) != 0)
set_range(previous_size, 8 - previous_size % 8, default_value); set_range(previous_size, 8 - previous_size % 8, default_value);
kfree_sized(previous_data, previous_size_bytes); kfree_sized(previous_data, previous_size_bytes);
} }

View File

@ -86,7 +86,7 @@ public:
return count; return count;
} }
[[nodiscard]] bool is_null() const { return !m_data; } [[nodiscard]] bool is_null() const { return m_data == nullptr; }
[[nodiscard]] const u8* data() const { return m_data; } [[nodiscard]] const u8* data() const { return m_data; }
@ -279,7 +279,7 @@ public:
size_t trailing_bits = size() % 32; size_t trailing_bits = size() % 32;
for (size_t i = 0; i < trailing_bits; ++i) { for (size_t i = 0; i < trailing_bits; ++i) {
if (!get(first_trailing_bit + i)) { if (!get(first_trailing_bit + i)) {
if (!free_chunks) if (free_chunks == 0)
*start_of_free_chunks = first_trailing_bit + i; *start_of_free_chunks = first_trailing_bit + i;
if (++free_chunks >= min_length) if (++free_chunks >= min_length)
return min(free_chunks, max_length); return min(free_chunks, max_length);
@ -313,7 +313,7 @@ public:
} }
found_range_size = max_region_size; found_range_size = max_region_size;
if (max_region_size) { if (max_region_size != 0) {
return max_region_start; return max_region_start;
} }
return {}; return {};

View File

@ -118,7 +118,7 @@ public:
return data()[i]; return data()[i];
} }
[[nodiscard]] bool is_empty() const { return !m_size; } [[nodiscard]] bool is_empty() const { return m_size == 0; }
[[nodiscard]] size_t size() const { return m_size; } [[nodiscard]] size_t size() const { return m_size; }
[[nodiscard]] u8* data() { return m_inline ? m_inline_buffer : m_outline_buffer; } [[nodiscard]] u8* data() { return m_inline ? m_inline_buffer : m_outline_buffer; }

View File

@ -33,7 +33,7 @@ public:
m_size = 0; m_size = 0;
} }
bool is_empty() const { return !m_size; } bool is_empty() const { return m_size == 0; }
size_t size() const { return m_size; } size_t size() const { return m_size; }
size_t capacity() const { return Capacity; } size_t capacity() const { return Capacity; }

View File

@ -181,7 +181,7 @@ public:
swap(a.m_collection_data, b.m_collection_data); swap(a.m_collection_data, b.m_collection_data);
} }
[[nodiscard]] bool is_empty() const { return !m_size; } [[nodiscard]] bool is_empty() const { return m_size == 0; }
[[nodiscard]] size_t size() const { return m_size; } [[nodiscard]] size_t size() const { return m_size; }
[[nodiscard]] size_t capacity() const { return m_capacity; } [[nodiscard]] size_t capacity() const { return m_capacity; }

View File

@ -60,7 +60,7 @@ public:
{ {
if (length() != other.length()) if (length() != other.length())
return false; return false;
return !__builtin_memcmp(characters(), other.characters(), length()); return __builtin_memcmp(characters(), other.characters(), length()) == 0;
} }
unsigned hash() const unsigned hash() const

View File

@ -52,7 +52,7 @@ public:
explicit StringView(String&&) = delete; explicit StringView(String&&) = delete;
explicit StringView(FlyString&&) = delete; explicit StringView(FlyString&&) = delete;
[[nodiscard]] constexpr bool is_null() const { return !m_characters; } [[nodiscard]] constexpr bool is_null() const { return m_characters == nullptr; }
[[nodiscard]] constexpr bool is_empty() const { return m_length == 0; } [[nodiscard]] constexpr bool is_empty() const { return m_length == 0; }
[[nodiscard]] constexpr char const* characters_without_null_termination() const { return m_characters; } [[nodiscard]] constexpr char const* characters_without_null_termination() const { return m_characters; }
@ -151,18 +151,18 @@ public:
constexpr bool operator==(const char* cstring) const constexpr bool operator==(const char* cstring) const
{ {
if (is_null()) if (is_null())
return !cstring; return cstring == nullptr;
if (!cstring) if (!cstring)
return false; return false;
// NOTE: `m_characters` is not guaranteed to be null-terminated, but `cstring` is. // NOTE: `m_characters` is not guaranteed to be null-terminated, but `cstring` is.
const char* cp = cstring; const char* cp = cstring;
for (size_t i = 0; i < m_length; ++i) { for (size_t i = 0; i < m_length; ++i) {
if (!*cp) if (*cp == '\0')
return false; return false;
if (m_characters[i] != *(cp++)) if (m_characters[i] != *(cp++))
return false; return false;
} }
return !*cp; return *cp == '\0';
} }
constexpr bool operator!=(const char* cstring) const constexpr bool operator!=(const char* cstring) const
@ -180,7 +180,7 @@ public:
return false; return false;
if (length() != other.length()) if (length() != other.length())
return false; return false;
return !__builtin_memcmp(m_characters, other.m_characters, m_length); return __builtin_memcmp(m_characters, other.m_characters, m_length) == 0;
} }
constexpr bool operator!=(StringView other) const constexpr bool operator!=(StringView other) const

View File

@ -50,7 +50,7 @@ inline bool is_leap_year(int year)
inline int days_in_year(int year) inline int days_in_year(int year)
{ {
return 365 + is_leap_year(year); return 365 + (is_leap_year(year) ? 1 : 0);
} }
inline int years_to_days_since_epoch(int year) inline int years_to_days_since_epoch(int year)
@ -163,7 +163,7 @@ public:
// Rounds towards -inf (it was the easiest to implement). // Rounds towards -inf (it was the easiest to implement).
[[nodiscard]] timeval to_timeval() const; [[nodiscard]] timeval to_timeval() const;
[[nodiscard]] bool is_zero() const { return !m_seconds && !m_nanoseconds; } [[nodiscard]] bool is_zero() const { return (m_seconds == 0) && (m_nanoseconds == 0); }
[[nodiscard]] bool is_negative() const { return m_seconds < 0; } [[nodiscard]] bool is_negative() const { return m_seconds < 0; }
bool operator==(const Time& other) const { return this->m_seconds == other.m_seconds && this->m_nanoseconds == other.m_nanoseconds; } bool operator==(const Time& other) const { return this->m_seconds == other.m_seconds && this->m_nanoseconds == other.m_nanoseconds; }

View File

@ -15,7 +15,7 @@ class TypedTransfer {
public: public:
static void move(T* destination, T* source, size_t count) static void move(T* destination, T* source, size_t count)
{ {
if (!count) if (count == 0)
return; return;
if constexpr (Traits<T>::is_trivial()) { if constexpr (Traits<T>::is_trivial()) {
@ -29,13 +29,11 @@ public:
else else
new (&destination[count - i - 1]) T(std::move(source[count - i - 1])); new (&destination[count - i - 1]) T(std::move(source[count - i - 1]));
} }
return;
} }
static size_t copy(T* destination, const T* source, size_t count) static size_t copy(T* destination, const T* source, size_t count)
{ {
if (!count) if (count == 0)
return 0; return 0;
if constexpr (Traits<T>::is_trivial()) { if constexpr (Traits<T>::is_trivial()) {
@ -55,7 +53,7 @@ public:
static bool compare(const T* a, const T* b, size_t count) static bool compare(const T* a, const T* b, size_t count)
{ {
if (!count) if (count == 0)
return true; return true;
if constexpr (Traits<T>::is_trivial()) if constexpr (Traits<T>::is_trivial())

View File

@ -20,7 +20,6 @@ class Userspace {
public: public:
Userspace() = default; Userspace() = default;
operator bool() const { return m_ptr; }
operator FlatPtr() const { return (FlatPtr)m_ptr; } operator FlatPtr() const { return (FlatPtr)m_ptr; }
// Disable default implementations that would use surprising integer promotion. // Disable default implementations that would use surprising integer promotion.
@ -36,6 +35,8 @@ public:
{ {
} }
explicit operator bool() const { return m_ptr != 0; }
FlatPtr ptr() const { return m_ptr; } FlatPtr ptr() const { return m_ptr; }
T unsafe_userspace_ptr() const { return (T)m_ptr; } T unsafe_userspace_ptr() const { return (T)m_ptr; }
#else #else
@ -44,6 +45,8 @@ public:
{ {
} }
explicit operator bool() const { return m_ptr != nullptr; }
T ptr() const { return m_ptr; } T ptr() const { return m_ptr; }
#endif #endif

View File

@ -520,7 +520,7 @@ public:
ErrorOr<void> try_append(StorageType const* values, size_t count) ErrorOr<void> try_append(StorageType const* values, size_t count)
{ {
if (!count) if (count == 0)
return {}; return {};
TRY(try_grow_capacity(size() + count)); TRY(try_grow_capacity(size() + count));
TypedTransfer<StorageType>::copy(slot(m_size), values, count); TypedTransfer<StorageType>::copy(slot(m_size), values, count);
@ -569,7 +569,7 @@ public:
ErrorOr<void> try_prepend(StorageType const* values, size_t count) ErrorOr<void> try_prepend(StorageType const* values, size_t count)
{ {
if (!count) if (count == 0)
return {}; return {};
TRY(try_grow_capacity(size() + count)); TRY(try_grow_capacity(size() + count));
TypedTransfer<StorageType>::move(slot(count), slot(0), m_size); TypedTransfer<StorageType>::move(slot(count), slot(0), m_size);
@ -645,7 +645,7 @@ public:
if (new_size == size()) if (new_size == size())
return; return;
if (!new_size) { if (new_size == 0) {
if (keep_capacity) if (keep_capacity)
clear_with_capacity(); clear_with_capacity();
else else

View File

@ -66,7 +66,7 @@ public:
bool is_null() const bool is_null() const
{ {
return !unsafe_ptr<void>(); return unsafe_ptr<void>() == nullptr;
} }
void revoke() void revoke()