From a022d3856ac7e05e82e614bdc68403c50ea899b9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 22 Feb 2019 21:14:37 -0800 Subject: [PATCH] micro optimize setting up the storage length SmallVec::resize showed up as a hot spot in the profiler --- termwiz/src/cell.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/termwiz/src/cell.rs b/termwiz/src/cell.rs index bb5d5fe69..c1fef7b76 100644 --- a/termwiz/src/cell.rs +++ b/termwiz/src/cell.rs @@ -225,7 +225,9 @@ impl Cell { pub fn new(text: char, attrs: CellAttributes) -> Self { let len = text.len_utf8(); let mut storage = SmallVec::with_capacity(len); - storage.resize(len, 0); + unsafe { + storage.set_len(len); + } text.encode_utf8(&mut storage); Self::nerf_control_char(&mut storage);