Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Patch

- Allocate exact length when building an encoding from a specification
- Clarify wrapping behavior on empty output in documentation
- Fix `redundant_explicit_links` rustdoc lint
- Rename lints in `Cargo.toml` to use underscores
Expand Down
7 changes: 5 additions & 2 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,9 @@ impl Specification {
check!(SpecificationError(Undefined(to[i])), v != INVALID);
set(&mut values, from[i], v)?;
}
let mut encoding = Vec::new();
let has_ignore = values.contains(&IGNORE);
let capacity = 514 + has_ignore as usize + wrap.map_or(0, |(_, end)| end.len());
let mut encoding = Vec::with_capacity(capacity);
for _ in 0 .. 256 / symbols.len() {
encoding.extend_from_slice(symbols);
}
Expand All @@ -2003,9 +2005,10 @@ impl Specification {
if let Some((col, end)) = wrap {
encoding.push(col);
encoding.extend_from_slice(end);
} else if values.contains(&IGNORE) {
} else if has_ignore {
encoding.push(0);
}
debug_assert_eq!(encoding.len(), capacity);
Ok(Encoding(Cow::Owned(encoding)))
}
}
Expand Down
Loading