Files
zed/crates
Parker Loflin fb62376caa agent: Read buffer length without copying the text (#66981)
## Summary

`get_buffer_content_or_outline` chooses between a file's full text and
its outline by size. It measured the size with `buffer.text().len()`,
which copies the whole buffer into a `String`. `buffer.len()` reads the
same length from the rope's summary.

This runs on the main thread when the read file tool reads a file
without a line range and when a file is mentioned as context.

Both expressions timed on a `text::Buffer` in a release build:

| Buffer size | `text().len()` | `len()` |
|---|---|---|
| 16 KB | 1.8 µs | < 0.1 µs |
| 256 KB | 25 µs | < 0.1 µs |
| 4 MB | 398 µs | < 0.1 µs |
| 64 MB | 22 ms | < 0.1 µs |

## Testing

`cargo test -p agent --lib outline` passes.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- N/A
2026-11-15 09:13:10 +00:00
..
…
2026-11-11 19:41:39 +00:00
…
…
…
…
…
…
…
…
…