Skip to content

Commit

Permalink
refactor(filter): Simplify allocation avoidance
Browse files Browse the repository at this point in the history
Cherry pick fdc4358 (assert-rs#279)
  • Loading branch information
epage committed May 16, 2024
1 parent 5c9fe2e commit b283dd9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/snapbox/src/filter/redactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ impl Redactions {
}

fn clear<'v>(&self, pattern: &'v str) -> Cow<'v, str> {
if pattern.contains('[') {
let mut pattern = Cow::Borrowed(pattern);
if !self.unused.is_empty() && pattern.contains('[') {
let mut pattern = pattern.to_owned();
for var in self.unused.iter() {
pattern = Cow::Owned(pattern.replace(var, ""));
pattern = pattern.replace(var, "");
}
pattern
Cow::Owned(pattern)
} else {
Cow::Borrowed(pattern)
}
Expand Down

0 comments on commit b283dd9

Please sign in to comment.