mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
AK: Remove Optional::operator bool()
This was causing some obvious-in-hindsight but hard to spot bugs where we'd implicitly convert the bool to an integer type and carry on with the number 1 instead of the actual value().
This commit is contained in:
parent
ae233c1e82
commit
8bb361889c
6 changed files with 9 additions and 12 deletions
|
@ -165,14 +165,14 @@ public:
|
||||||
if (!first_index.has_value())
|
if (!first_index.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
size_t free_region_start = first_index;
|
size_t free_region_start = first_index.value();
|
||||||
size_t free_region_size = 1;
|
size_t free_region_size = 1;
|
||||||
|
|
||||||
size_t max_region_start = free_region_start;
|
size_t max_region_start = free_region_start;
|
||||||
size_t max_region_size = free_region_size;
|
size_t max_region_size = free_region_size;
|
||||||
|
|
||||||
// Let's try and find the best fit possible
|
// Let's try and find the best fit possible
|
||||||
for (size_t j = first_index + 1; j < m_size && free_region_size < max_length; j++) {
|
for (size_t j = first_index.value() + 1; j < m_size && free_region_size < max_length; j++) {
|
||||||
if (!get(j)) {
|
if (!get(j)) {
|
||||||
if (free_region_size == 0)
|
if (free_region_size == 0)
|
||||||
free_region_start = j;
|
free_region_start = j;
|
||||||
|
|
|
@ -150,9 +150,6 @@ public:
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_TYPESTATE(consumed)
|
|
||||||
operator bool() const { return m_has_value; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Call when we don't want to alter the consume state
|
// Call when we don't want to alter the consume state
|
||||||
const T& value_without_consume_state() const
|
const T& value_without_consume_state() const
|
||||||
|
|
|
@ -1076,9 +1076,9 @@ Ext2FS::BlockIndex Ext2FS::allocate_block(GroupIndex preferred_group_index)
|
||||||
auto block_bitmap = Bitmap::wrap(cached_bitmap.buffer.data(), blocks_in_group);
|
auto block_bitmap = Bitmap::wrap(cached_bitmap.buffer.data(), blocks_in_group);
|
||||||
|
|
||||||
BlockIndex first_block_in_group = (group_index - 1) * blocks_per_group() + first_block_index();
|
BlockIndex first_block_in_group = (group_index - 1) * blocks_per_group() + first_block_index();
|
||||||
int first_unset_bit_index = block_bitmap.find_first_unset();
|
auto first_unset_bit_index = block_bitmap.find_first_unset();
|
||||||
ASSERT(first_unset_bit_index != -1);
|
ASSERT(first_unset_bit_index.has_value());
|
||||||
BlockIndex block_index = (unsigned)first_unset_bit_index + first_block_in_group;
|
BlockIndex block_index = first_unset_bit_index.value() + first_block_in_group;
|
||||||
set_block_allocation_state(block_index, true);
|
set_block_allocation_state(block_index, true);
|
||||||
return block_index;
|
return block_index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1228,7 +1228,7 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
||||||
if (!description) {
|
if (!description) {
|
||||||
generated_data = (*read_callback)(identifier());
|
generated_data = (*read_callback)(identifier());
|
||||||
} else {
|
} else {
|
||||||
if (!description->generator_cache())
|
if (!description->generator_cache().has_value())
|
||||||
description->generator_cache() = (*read_callback)(identifier());
|
description->generator_cache() = (*read_callback)(identifier());
|
||||||
generated_data = description->generator_cache();
|
generated_data = description->generator_cache();
|
||||||
}
|
}
|
||||||
|
@ -1242,7 +1242,7 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
||||||
|
|
||||||
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
|
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
|
||||||
memcpy(buffer, data.value().data() + offset, nread);
|
memcpy(buffer, data.value().data() + offset, nread);
|
||||||
if (nread == 0 && description && description->generator_cache())
|
if (nread == 0 && description && description->generator_cache().has_value())
|
||||||
description->generator_cache().clear();
|
description->generator_cache().clear();
|
||||||
|
|
||||||
return nread;
|
return nread;
|
||||||
|
|
|
@ -209,7 +209,7 @@ NonnullRefPtr<StyleProperties> Element::computed_style()
|
||||||
};
|
};
|
||||||
for (CSS::PropertyID id : box_model_metrics) {
|
for (CSS::PropertyID id : box_model_metrics) {
|
||||||
auto prop = layout_node()->style().property(id);
|
auto prop = layout_node()->style().property(id);
|
||||||
if (prop)
|
if (prop.has_value())
|
||||||
properties->set_property(id, prop.value());
|
properties->set_property(id, prop.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
|
||||||
|
|
||||||
Vector<String> responses;
|
Vector<String> responses;
|
||||||
|
|
||||||
if (auto known_host = m_etc_hosts.get(hostname)) {
|
if (auto known_host = m_etc_hosts.get(hostname); known_host.has_value()) {
|
||||||
responses.append(known_host.value());
|
responses.append(known_host.value());
|
||||||
} else if (!hostname.is_empty()) {
|
} else if (!hostname.is_empty()) {
|
||||||
bool did_timeout;
|
bool did_timeout;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue