From 45829b33805a45f6edc9d13fcd3806933b9a91e8 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 8 Dec 2025 16:01:46 -0800 Subject: [PATCH] Avoid the cost of creating an anyhow error in RelPath::strip_prefix (#44444) Release Notes: - Fixed a performance bottleneck that could delay Zed's processing FS events for a long time in some cases. --- crates/util/src/rel_path.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/util/src/rel_path.rs b/crates/util/src/rel_path.rs index 8b6ae6e49a67ae1ef2d21b3b1e0c4708f407a5e3..5e20aacad5fe177cd1af65dc98aeb45565a3082e 100644 --- a/crates/util/src/rel_path.rs +++ b/crates/util/src/rel_path.rs @@ -161,7 +161,7 @@ impl RelPath { false } - pub fn strip_prefix<'a>(&'a self, other: &Self) -> Result<&'a Self> { + pub fn strip_prefix<'a>(&'a self, other: &Self) -> Result<&'a Self, StripPrefixError> { if other.is_empty() { return Ok(self); } @@ -172,7 +172,7 @@ impl RelPath { return Ok(Self::empty()); } } - Err(anyhow!("failed to strip prefix: {other:?} from {self:?}")) + Err(StripPrefixError) } pub fn len(&self) -> usize { @@ -251,6 +251,9 @@ impl RelPath { } } +#[derive(Debug)] +pub struct StripPrefixError; + impl ToOwned for RelPath { type Owned = RelPathBuf;