summaryrefslogtreecommitdiff
path: root/Userland/Applications/HexEditor/HexEditor.cpp
diff options
context:
space:
mode:
authorJames Puleo <james@jame.xyz>2022-07-28 03:34:15 -0400
committerTim Flynn <trflynn89@pm.me>2022-08-03 10:12:11 -0400
commit88cf40179dc8f6e977b838bc046f53155d38b9e4 (patch)
tree88bfb742cf2002b6d01b6a34062d7ac841003583 /Userland/Applications/HexEditor/HexEditor.cpp
parent035d63f5280c9ecc5241770841ccc782991922c2 (diff)
downloadserenity-88cf40179dc8f6e977b838bc046f53155d38b9e4.zip
HexEditor: Make `HexEditor::open_new_file` fallible and reduce branching
Returning a `bool` is meaningless, so let's make it more expresive :^)
Diffstat (limited to 'Userland/Applications/HexEditor/HexEditor.cpp')
-rw-r--r--Userland/Applications/HexEditor/HexEditor.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp
index d27c7f9cd7..addf4047fe 100644
--- a/Userland/Applications/HexEditor/HexEditor.cpp
+++ b/Userland/Applications/HexEditor/HexEditor.cpp
@@ -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)