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.
This commit is contained in:
Max Brunsfeld
2025-12-09 00:01:46 +00:00
committed by GitHub
parent 631e3dd272
commit 45829b3380
+5 -2
View File
@@ -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;