assistant_tools: Reduce allocations (#30776)

Another batch of allocation savings. Noteworthy ones are
`find_path_tool.rs` where one clone of *all* found matches was saved and
`web_tool_search.rs` where the tooltip no longer clones the entire url
on every hover.

I'd also like to propose using `std::borrow::Cow` a lot more around the
codebase instead of Strings. There are hundreds if not 1000+ clones that
can be saved pretty regularly simply by switching to Cow. ´Cow´'s are
likely not used because they aren't compatible with futures and because
it could cause lifetime bloat. However if we use `Cow<'static, str>`
(static lifetime) for when we need to pass them into futures, we could
save a TON of allocations for `&'static str`. Additionally I often see
structs being created using `String`'s just to be deserialized
afterwards, which only requires a reference.

Release Notes:

- N/A
This commit is contained in:
tidely 2025-05-30 18:28:22 +03:00 committed by GitHub
parent 047e7eacec
commit 8bec4cbecb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 19 deletions

View file

@ -182,9 +182,8 @@ impl Tool for TerminalTool {
let mut child = pair.slave.spawn_command(cmd)?;
let mut reader = pair.master.try_clone_reader()?;
drop(pair);
let mut content = Vec::new();
reader.read_to_end(&mut content)?;
let mut content = String::from_utf8(content)?;
let mut content = String::new();
reader.read_to_string(&mut content)?;
// Massage the pty output a bit to try to match what the terminal codepath gives us
LineEnding::normalize(&mut content);
content = content