1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

HexEditor: Make HexEditor::open_new_file fallible and reduce branching

Returning a `bool` is meaningless, so let's make it more expresive :^)
This commit is contained in:
James Puleo 2022-07-28 03:34:15 -04:00 committed by Tim Flynn
parent 035d63f528
commit 88cf40179d
3 changed files with 15 additions and 18 deletions

View file

@ -49,14 +49,9 @@ HexEditor::HexEditor()
m_blink_timer->start();
}
bool HexEditor::open_new_file(size_t size)
ErrorOr<void> HexEditor::open_new_file(size_t size)
{
auto maybe_buffer = ByteBuffer::create_zeroed(size);
if (maybe_buffer.is_error()) {
return false;
}
m_document = make<HexDocumentMemory>(maybe_buffer.release_value());
m_document = make<HexDocumentMemory>(TRY(ByteBuffer::create_zeroed(size)));
set_content_length(m_document->size());
m_position = 0;
m_cursor_at_low_nibble = false;
@ -66,7 +61,7 @@ bool HexEditor::open_new_file(size_t size)
update();
update_status();
return true;
return {};
}
void HexEditor::open_file(NonnullRefPtr<Core::File> file)