diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-11-27 09:55:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 04:55:21 -0500 |
commit | 46b7881fb0d13034567278af6712ac601319bc59 (patch) | |
tree | 2ff55dad2ba1a103e1bef32ba3d744ee7307ef75 | |
parent | 590f03bd69638e71249647beb8768f7154838671 (diff) |
other: preallocate space for ellipsis (#1336)
-rw-r--r-- | src/utils/gen_util.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs index 4b6f8e4e..20df9bb7 100644 --- a/src/utils/gen_util.rs +++ b/src/utils/gen_util.rs @@ -106,7 +106,8 @@ enum AsciiIterationResult { fn greedy_ascii_add(content: &str, width: NonZeroUsize) -> (String, AsciiIterationResult) { let width: usize = width.into(); - let mut text = Vec::with_capacity(width); + const SIZE_OF_ELLIPSIS: usize = 3; + let mut text = Vec::with_capacity(width - 1 + SIZE_OF_ELLIPSIS); let s = content.as_bytes(); @@ -134,7 +135,7 @@ fn greedy_ascii_add(content: &str, width: NonZeroUsize) -> (String, AsciiIterati debug_assert!(text.is_ascii()); let current_index = if s[current_index].is_ascii() { - let mut ellipsis = [0; 3]; + let mut ellipsis = [0; SIZE_OF_ELLIPSIS]; '…'.encode_utf8(&mut ellipsis); text.extend_from_slice(&ellipsis); AsciiIterationResult::Complete |