From c23060e21bf5831250624cd286e97d2081f8f0d6 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 3 Apr 2024 21:44:40 -0400 Subject: [PATCH] Userland: Avoid some now-unneeded explicit conversions to Bytes --- Tests/LibJS/test-test262.cpp | 2 +- .../NetworkSettings/NetworkSettingsWidget.cpp | 2 +- .../Applications/PixelPaint/PaletteWidget.cpp | 2 +- Userland/Applications/Run/RunWindow.cpp | 2 +- .../DevTools/HackStudio/ProjectBuilder.cpp | 2 +- Userland/Libraries/LibCore/Command.cpp | 2 +- Userland/Libraries/LibCore/ConfigFile.cpp | 6 ++--- Userland/Libraries/LibGUI/TextEditor.cpp | 4 +-- Userland/Libraries/LibLine/Editor.cpp | 25 +++++++++---------- .../LibLine/XtermSuggestionDisplay.cpp | 2 +- Userland/Libraries/LibSQL/SQLClient.cpp | 2 +- Userland/Libraries/LibTLS/HandshakeClient.cpp | 10 ++++---- Userland/Utilities/uniq.cpp | 4 +-- Userland/Utilities/utmpupdate.cpp | 2 +- Userland/Utilities/wasm.cpp | 12 ++++----- 15 files changed, 39 insertions(+), 40 deletions(-) diff --git a/Tests/LibJS/test-test262.cpp b/Tests/LibJS/test-test262.cpp index cbb8d2082a8..30d6433f80e 100644 --- a/Tests/LibJS/test-test262.cpp +++ b/Tests/LibJS/test-test262.cpp @@ -320,7 +320,7 @@ void write_per_file(HashMap const& result_map, Vectorwrite_until_depleted(complete_results.to_byte_string().bytes()).is_error()) + if (file->write_until_depleted(complete_results.to_byte_string()).is_error()) warnln("Failed to write per-file"); file->close(); } diff --git a/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp b/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp index e45a3fe4b4e..620dfdfd59c 100644 --- a/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp +++ b/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp @@ -165,7 +165,7 @@ ErrorOr NetworkSettingsWidget::apply_settings_impl() (void)TRY(Core::System::posix_spawn("/bin/Escalator"sv, &file_actions, nullptr, const_cast(argv), environ)); auto outfile = TRY(Core::File::adopt_fd(pipefds[1], Core::File::OpenMode::Write, Core::File::ShouldCloseFileDescriptor::No)); - TRY(outfile->write_until_depleted(json.serialized().bytes())); + TRY(outfile->write_until_depleted(json.serialized())); } return {}; diff --git a/Userland/Applications/PixelPaint/PaletteWidget.cpp b/Userland/Applications/PixelPaint/PaletteWidget.cpp index 9bc76cd8ce8..849c0703556 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.cpp +++ b/Userland/Applications/PixelPaint/PaletteWidget.cpp @@ -249,7 +249,7 @@ ErrorOr> PaletteWidget::load_palette_path(ByteString const& file_p ErrorOr PaletteWidget::save_palette_file(Vector palette, NonnullOwnPtr file) { for (auto& color : palette) { - TRY(file->write_until_depleted(color.to_byte_string_without_alpha().bytes())); + TRY(file->write_until_depleted(color.to_byte_string_without_alpha())); TRY(file->write_until_depleted({ "\n", 1 })); } return {}; diff --git a/Userland/Applications/Run/RunWindow.cpp b/Userland/Applications/Run/RunWindow.cpp index 00db397147f..fd9c4a6ce17 100644 --- a/Userland/Applications/Run/RunWindow.cpp +++ b/Userland/Applications/Run/RunWindow.cpp @@ -188,7 +188,7 @@ ErrorOr RunWindow::save_history() // Write the first 25 items of history for (int i = 0; i < min(static_cast(m_path_history.size()), 25); i++) - TRY(file->write_until_depleted(ByteString::formatted("{}\n", m_path_history[i]).bytes())); + TRY(file->write_until_depleted(ByteString::formatted("{}\n", m_path_history[i]))); return {}; } diff --git a/Userland/DevTools/HackStudio/ProjectBuilder.cpp b/Userland/DevTools/HackStudio/ProjectBuilder.cpp index cf39e50f153..6f8a2703334 100644 --- a/Userland/DevTools/HackStudio/ProjectBuilder.cpp +++ b/Userland/DevTools/HackStudio/ProjectBuilder.cpp @@ -135,7 +135,7 @@ ErrorOr ProjectBuilder::initialize_build_directory() MUST(FileSystem::remove(cmake_file_path, FileSystem::RecursionMode::Disallowed)); auto cmake_file = TRY(Core::File::open(cmake_file_path, Core::File::OpenMode::Write)); - TRY(cmake_file->write_until_depleted(generate_cmake_file_content().bytes())); + TRY(cmake_file->write_until_depleted(generate_cmake_file_content())); TRY(m_terminal->run_command(ByteString::formatted("cmake -S {} -DHACKSTUDIO_BUILD=ON -DHACKSTUDIO_BUILD_CMAKE_FILE={}" " -DENABLE_UNICODE_DATABASE_DOWNLOAD=OFF", diff --git a/Userland/Libraries/LibCore/Command.cpp b/Userland/Libraries/LibCore/Command.cpp index 5c24d7c2b1b..f7120b08790 100644 --- a/Userland/Libraries/LibCore/Command.cpp +++ b/Userland/Libraries/LibCore/Command.cpp @@ -85,7 +85,7 @@ ErrorOr Command::write_lines(Span lines) }); for (ByteString const& line : lines) - TRY(m_stdin->write_until_depleted(ByteString::formatted("{}\n", line).bytes())); + TRY(m_stdin->write_until_depleted(ByteString::formatted("{}\n", line))); return {}; } diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp index 6951cbf6939..95fe520109f 100644 --- a/Userland/Libraries/LibCore/ConfigFile.cpp +++ b/Userland/Libraries/LibCore/ConfigFile.cpp @@ -178,10 +178,10 @@ ErrorOr ConfigFile::sync() TRY(m_file->seek(0, SeekMode::SetPosition)); for (auto& it : m_groups) { - TRY(m_file->write_until_depleted(ByteString::formatted("[{}]\n", it.key).bytes())); + TRY(m_file->write_until_depleted(ByteString::formatted("[{}]\n", it.key))); for (auto& jt : it.value) - TRY(m_file->write_until_depleted(ByteString::formatted("{}={}\n", jt.key, jt.value).bytes())); - TRY(m_file->write_until_depleted("\n"sv.bytes())); + TRY(m_file->write_until_depleted(ByteString::formatted("{}={}\n", jt.key, jt.value))); + TRY(m_file->write_until_depleted("\n"sv)); } m_dirty = false; diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index beac385f592..e46059e8bd5 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -1704,8 +1704,8 @@ ErrorOr TextEditor::write_to_file(Core::File& file) // A size 0 file doesn't need a data copy. } else { for (size_t i = 0; i < line_count(); ++i) { - TRY(file.write_until_depleted(line(i).to_utf8().bytes())); - TRY(file.write_until_depleted("\n"sv.bytes())); + TRY(file.write_until_depleted(line(i).to_utf8())); + TRY(file.write_until_depleted("\n"sv)); } } document().set_unmodified(); diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 8c8d9af43e9..fb2d553b8d6 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -1646,7 +1646,7 @@ ErrorOr Editor::reposition_cursor(Stream& stream, bool to_end) ErrorOr VT::move_absolute(u32 row, u32 col, Stream& stream) { - return stream.write_until_depleted(ByteString::formatted("\033[{};{}H", row, col).bytes()); + return stream.write_until_depleted(ByteString::formatted("\033[{};{}H", row, col)); } ErrorOr VT::move_relative(int row, int col, Stream& stream) @@ -1663,9 +1663,9 @@ ErrorOr VT::move_relative(int row, int col, Stream& stream) col = -col; if (row > 0) - TRY(stream.write_until_depleted(ByteString::formatted("\033[{}{}", row, x_op).bytes())); + TRY(stream.write_until_depleted(ByteString::formatted("\033[{}{}", row, x_op))); if (col > 0) - TRY(stream.write_until_depleted(ByteString::formatted("\033[{}{}", col, y_op).bytes())); + TRY(stream.write_until_depleted(ByteString::formatted("\033[{}{}", col, y_op))); return {}; } @@ -1812,10 +1812,9 @@ ErrorOr VT::apply_style(Style const& style, Stream& stream, bool is_starti style.italic() ? 3 : 23, style.background().to_vt_escape(), style.foreground().to_vt_escape(), - style.hyperlink().to_vt_escape(true)) - .bytes())); + style.hyperlink().to_vt_escape(true)))); } else { - TRY(stream.write_until_depleted(style.hyperlink().to_vt_escape(false).bytes())); + TRY(stream.write_until_depleted(style.hyperlink().to_vt_escape(false))); } return {}; @@ -1824,16 +1823,16 @@ ErrorOr VT::apply_style(Style const& style, Stream& stream, bool is_starti ErrorOr VT::clear_lines(size_t count_above, size_t count_below, Stream& stream) { if (count_below + count_above == 0) { - TRY(stream.write_until_depleted("\033[2K"sv.bytes())); + TRY(stream.write_until_depleted("\033[2K"sv)); } else { // Go down count_below lines. if (count_below > 0) - TRY(stream.write_until_depleted(ByteString::formatted("\033[{}B", count_below).bytes())); + TRY(stream.write_until_depleted(ByteString::formatted("\033[{}B", count_below))); // Then clear lines going upwards. for (size_t i = count_below + count_above; i > 0; --i) { - TRY(stream.write_until_depleted("\033[2K"sv.bytes())); + TRY(stream.write_until_depleted("\033[2K"sv)); if (i != 1) - TRY(stream.write_until_depleted("\033[A"sv.bytes())); + TRY(stream.write_until_depleted("\033[A"sv)); } } @@ -1842,17 +1841,17 @@ ErrorOr VT::clear_lines(size_t count_above, size_t count_below, Stream& st ErrorOr VT::save_cursor(Stream& stream) { - return stream.write_until_depleted("\033[s"sv.bytes()); + return stream.write_until_depleted("\033[s"sv); } ErrorOr VT::restore_cursor(Stream& stream) { - return stream.write_until_depleted("\033[u"sv.bytes()); + return stream.write_until_depleted("\033[u"sv); } ErrorOr VT::clear_to_end_of_line(Stream& stream) { - return stream.write_until_depleted("\033[K"sv.bytes()); + return stream.write_until_depleted("\033[K"sv); } enum VTState { diff --git a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp index f7af1e7394f..db236224e8d 100644 --- a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp +++ b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp @@ -119,7 +119,7 @@ ErrorOr XtermSuggestionDisplay::display(SuggestionManager const& manager) TRY(stderr_stream->write_until_depleted(suggestion.display_trivia_string().bytes())); } else { auto field = ByteString::formatted("{: <{}} {}", suggestion.text_string(), longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string()); - TRY(stderr_stream->write_until_depleted(ByteString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes())); + TRY(stderr_stream->write_until_depleted(ByteString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2))); num_printed += longest_suggestion_length + 2; } diff --git a/Userland/Libraries/LibSQL/SQLClient.cpp b/Userland/Libraries/LibSQL/SQLClient.cpp index 251e8516d36..aa099c43c55 100644 --- a/Userland/Libraries/LibSQL/SQLClient.cpp +++ b/Userland/Libraries/LibSQL/SQLClient.cpp @@ -75,7 +75,7 @@ static ErrorOr launch_server(ByteString const& socket_path, ByteString con if (server_pid != 0) { auto server_pid_file = TRY(Core::File::open(pid_path, Core::File::OpenMode::Write)); - TRY(server_pid_file->write_until_depleted(ByteString::number(server_pid).bytes())); + TRY(server_pid_file->write_until_depleted(ByteString::number(server_pid))); TRY(Core::System::kill(getpid(), SIGTERM)); } diff --git a/Userland/Libraries/LibTLS/HandshakeClient.cpp b/Userland/Libraries/LibTLS/HandshakeClient.cpp index 50ccb4d196d..158586dd09f 100644 --- a/Userland/Libraries/LibTLS/HandshakeClient.cpp +++ b/Userland/Libraries/LibTLS/HandshakeClient.cpp @@ -153,11 +153,11 @@ bool TLSv12::compute_master_secret_from_pre_master_secret(size_t length) if constexpr (TLS_SSL_KEYLOG_DEBUG) { auto file = MUST(Core::File::open("/home/anon/ssl_keylog"sv, Core::File::OpenMode::Append | Core::File::OpenMode::Write)); - MUST(file->write_until_depleted("CLIENT_RANDOM "sv.bytes())); - MUST(file->write_until_depleted(encode_hex({ m_context.local_random, 32 }).bytes())); - MUST(file->write_until_depleted(" "sv.bytes())); - MUST(file->write_until_depleted(encode_hex(m_context.master_key).bytes())); - MUST(file->write_until_depleted("\n"sv.bytes())); + MUST(file->write_until_depleted("CLIENT_RANDOM "sv)); + MUST(file->write_until_depleted(encode_hex({ m_context.local_random, 32 }))); + MUST(file->write_until_depleted(" "sv)); + MUST(file->write_until_depleted(encode_hex(m_context.master_key))); + MUST(file->write_until_depleted("\n"sv)); } expand_key(); diff --git a/Userland/Utilities/uniq.cpp b/Userland/Utilities/uniq.cpp index a7799830945..59e9a3e5c00 100644 --- a/Userland/Utilities/uniq.cpp +++ b/Userland/Utilities/uniq.cpp @@ -18,9 +18,9 @@ static ErrorOr write_line_content(StringView line, size_t count, bool dupl return {}; if (print_count) - TRY(outfile.write_until_depleted(ByteString::formatted("{} {}\n", count, line).bytes())); + TRY(outfile.write_until_depleted(ByteString::formatted("{} {}\n", count, line))); else - TRY(outfile.write_until_depleted(ByteString::formatted("{}\n", line).bytes())); + TRY(outfile.write_until_depleted(ByteString::formatted("{}\n", line))); return {}; } diff --git a/Userland/Utilities/utmpupdate.cpp b/Userland/Utilities/utmpupdate.cpp index f03a72e1e38..fe2acd0a996 100644 --- a/Userland/Utilities/utmpupdate.cpp +++ b/Userland/Utilities/utmpupdate.cpp @@ -72,7 +72,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(file->seek(0, SeekMode::SetPosition)); TRY(file->truncate(0)); - TRY(file->write_until_depleted(json.to_byte_string().bytes())); + TRY(file->write_until_depleted(json.to_byte_string())); return 0; } diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index 23be3bb624b..ae0a841ceb4 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -247,12 +247,12 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi if (always_print_stack) config.dump_stack(); if (always_print_instruction) { - g_stdout->write_until_depleted(ByteString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(ByteString::formatted("{:0>4} ", ip.value())).release_value_but_fixme_should_propagate_errors(); g_printer->print(instr); } if (g_continue) return true; - g_stdout->write_until_depleted(ByteString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(ByteString::formatted("{:0>4} ", ip.value())).release_value_but_fixme_should_propagate_errors(); g_printer->print(instr); ByteString last_command = ""; for (;;) { @@ -732,15 +732,15 @@ ErrorOr serenity_main(Main::Arguments arguments) auto print_func = [&](auto const& address) { Wasm::FunctionInstance* fn = machine.store().get(address); - g_stdout->write_until_depleted(ByteString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(ByteString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn)).release_value_but_fixme_should_propagate_errors(); if (fn) { - g_stdout->write_until_depleted(ByteString::formatted(" wasm function? {}\n", fn->has()).bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(ByteString::formatted(" wasm function? {}\n", fn->has())).release_value_but_fixme_should_propagate_errors(); fn->visit( [&](Wasm::WasmFunction const& func) { Wasm::Printer printer { *g_stdout, 3 }; - g_stdout->write_until_depleted(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(" type:\n"sv).release_value_but_fixme_should_propagate_errors(); printer.print(func.type()); - g_stdout->write_until_depleted(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors(); + g_stdout->write_until_depleted(" code:\n"sv).release_value_but_fixme_should_propagate_errors(); printer.print(func.code()); }, [](Wasm::HostFunction const&) {});