Userland: Avoid some now-unneeded explicit conversions to Bytes

This commit is contained in:
Timothy Flynn 2024-04-03 21:44:40 -04:00 committed by Andreas Kling
parent e0bddbb65e
commit c23060e21b
Notes: sideshowbarker 2024-07-17 01:51:00 +09:00
15 changed files with 39 additions and 40 deletions

View file

@ -320,7 +320,7 @@ void write_per_file(HashMap<size_t, TestResult> const& result_map, Vector<ByteSt
complete_results.set("duration", time_taken_in_ms / 1000.);
complete_results.set("results", result_object);
if (file->write_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();
}

View file

@ -165,7 +165,7 @@ ErrorOr<void> NetworkSettingsWidget::apply_settings_impl()
(void)TRY(Core::System::posix_spawn("/bin/Escalator"sv, &file_actions, nullptr, const_cast<char**>(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<StringBuilder>().bytes()));
TRY(outfile->write_until_depleted(json.serialized<StringBuilder>()));
}
return {};

View file

@ -249,7 +249,7 @@ ErrorOr<Vector<Color>> PaletteWidget::load_palette_path(ByteString const& file_p
ErrorOr<void> PaletteWidget::save_palette_file(Vector<Color> palette, NonnullOwnPtr<Core::File> 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 {};

View file

@ -188,7 +188,7 @@ ErrorOr<void> RunWindow::save_history()
// Write the first 25 items of history
for (int i = 0; i < min(static_cast<int>(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 {};
}

View file

@ -135,7 +135,7 @@ ErrorOr<void> 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",

View file

@ -85,7 +85,7 @@ ErrorOr<void> Command::write_lines(Span<ByteString> 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 {};
}

View file

@ -178,10 +178,10 @@ ErrorOr<void> 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;

View file

@ -1704,8 +1704,8 @@ ErrorOr<void> 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();

View file

@ -1646,7 +1646,7 @@ ErrorOr<void> Editor::reposition_cursor(Stream& stream, bool to_end)
ErrorOr<void> 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<void> VT::move_relative(int row, int col, Stream& stream)
@ -1663,9 +1663,9 @@ ErrorOr<void> 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<void> 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<void> VT::apply_style(Style const& style, Stream& stream, bool is_starti
ErrorOr<void> 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<void> VT::clear_lines(size_t count_above, size_t count_below, Stream& st
ErrorOr<void> VT::save_cursor(Stream& stream)
{
return stream.write_until_depleted("\033[s"sv.bytes());
return stream.write_until_depleted("\033[s"sv);
}
ErrorOr<void> VT::restore_cursor(Stream& stream)
{
return stream.write_until_depleted("\033[u"sv.bytes());
return stream.write_until_depleted("\033[u"sv);
}
ErrorOr<void> 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 {

View file

@ -119,7 +119,7 @@ ErrorOr<void> 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;
}

View file

@ -75,7 +75,7 @@ static ErrorOr<void> 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));
}

View file

@ -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();

View file

@ -18,9 +18,9 @@ static ErrorOr<void> 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 {};
}

View file

@ -72,7 +72,7 @@ ErrorOr<int> 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;
}

View file

@ -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<int> 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<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors();
g_stdout->write_until_depleted(ByteString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>())).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&) {});