Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable This PR makes two changes: 1. detect() now returns the line number of the first match instead of just a boolean. 2. This line number (line_hint) is threaded through the pipeline and passed as a subrange to query.search in full buffer scan, so the full buffer scan starts from where the first match was already found instead of the beginning of the file. ## Scope - This optimization only applies to **local search** (not remote). - It is only effective for **single-line text and single-line regex** queries. For multiline queries, `detect()` returns `line_hint = 0`, so the full buffer is scanned from the beginning as before. - It does not apply to already-open buffers, which always receive `line_hint = 0`. ## Test i tried to search the word "typeably" in the file "pkgs/development/haskell-modules/hackage-packages.nix" of the repo [nixpkgs](https://github.com/NixOS/nixpkgs) given in the comment: [comment](https://github.com/zed-industries/zed/issues/38799#issuecomment-4088491295). Result seems promising: **with line_hint: search: 45.21ms** **without line_hint: search: 508.05ms** I measured the time within the function: "handle_find_all_matches" ## Assumption The core assumption is: if the search query is long enough (after 4 or 5 chars), the probability of finding multiple matches in a single file is low. In that case, re-scanning the content before line_hint is unnecessary — detect() function already confirmed there is no match there. Changes maybe can make an improvement on issues #38799 and #58905 --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
4 files changedLine totals unavailable