refactor(pi-natives): reduced allocations in pattern deduplication
- normalize_pattern_list now skips all allocation for duplicate patterns and reuses the input String when trimming is a no-op.
This commit is contained in:
@@ -540,13 +540,16 @@ fn normalize_pattern_list(patterns: Option<Vec<String>>) -> Result<Vec<String>>
|
||||
let mut seen = BTreeSet::new();
|
||||
for raw in patterns.unwrap_or_default() {
|
||||
let pattern = raw.trim();
|
||||
if pattern.is_empty() {
|
||||
if pattern.is_empty() || seen.contains(pattern) {
|
||||
continue;
|
||||
}
|
||||
let owned = pattern.to_string();
|
||||
if seen.insert(owned.clone()) {
|
||||
normalized.push(owned);
|
||||
}
|
||||
let owned = if pattern.len() == raw.len() {
|
||||
raw
|
||||
} else {
|
||||
pattern.to_string()
|
||||
};
|
||||
seen.insert(owned.clone());
|
||||
normalized.push(owned);
|
||||
}
|
||||
if normalized.is_empty() {
|
||||
return Err(Error::from_reason(
|
||||
|
||||
Reference in New Issue
Block a user