From db80425a658e4e6b7d1348246b30fc539e5ce6bd Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 15 Jan 2023 00:32:39 -0500 Subject: [PATCH] LibGUI: Remove the `Core::File` overload of `write_to_file()` One less usage of `Core::File`, yay! --- Userland/Libraries/LibGUI/TextEditor.cpp | 43 ------------------------ Userland/Libraries/LibGUI/TextEditor.h | 1 - 2 files changed, 44 deletions(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 3d570148da..2f23fdad78 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -1465,49 +1465,6 @@ ErrorOr TextEditor::write_to_file(StringView path) return {}; } -bool TextEditor::write_to_file(Core::File& file) -{ - off_t file_size = 0; - if (line_count() == 1 && line(0).is_empty()) { - // Truncate to zero. - } else { - // Compute the final file size and ftruncate() to make writing fast. - // FIXME: Remove this once the kernel is smart enough to do this instead. - for (size_t i = 0; i < line_count(); ++i) - file_size += line(i).length(); - file_size += line_count(); - } - - if (!file.truncate(file_size)) { - perror("ftruncate"); - return false; - } - - if (file_size == 0) { - // A size 0 file doesn't need a data copy. - } else { - for (size_t i = 0; i < line_count(); ++i) { - auto& line = this->line(i); - if (line.length()) { - auto line_as_utf8 = line.to_utf8(); - ssize_t nwritten = file.write(line_as_utf8); - if (nwritten < 0) { - perror("write"); - return false; - } - } - char ch = '\n'; - ssize_t nwritten = file.write((u8*)&ch, 1); - if (nwritten != 1) { - perror("write"); - return false; - } - } - } - document().set_unmodified(); - return true; -} - ErrorOr TextEditor::write_to_file(Core::Stream::File& file) { off_t file_size = 0; diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index d071251ea4..34435a0a0e 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -130,7 +130,6 @@ public: void insert_at_cursor_or_replace_selection(StringView); void replace_all_text_without_resetting_undo_stack(StringView text); ErrorOr write_to_file(StringView path); - bool write_to_file(Core::File&); ErrorOr write_to_file(Core::Stream::File&); bool has_selection() const { return m_selection.is_valid(); } DeprecatedString selected_text() const;