optimize the allocation of the result vec

pull/40/head
Magic Len 7 years ago
parent aa909de48b
commit a61ab5a978

@ -125,7 +125,8 @@ fn compute_character_modes(code_points: &[char], version: Version) -> Vec<QrSegm
let mut cur_mode = cur_mode.unwrap();
let mut result = vec![QrSegmentMode::Byte; char_modes.len()];
let mut result = Vec::with_capacity(char_modes.len());
unsafe { result.set_len(char_modes.len()); }
// Get optimal mode for each code point by tracing backwards
for i in (0..char_modes.len()).rev() {
@ -240,4 +241,4 @@ fn is_kanji(_: char) -> bool {
#[cfg(feature = "kanji")]
// Load the unpacked the computation-friendly Shift JIS table
static UNICODE_TO_QR_KANJI: [i16; 1 << 16] = include!("unicode_to_qr_kanji.json");
static UNICODE_TO_QR_KANJI: [i16; 1 << 16] = include!("unicode_to_qr_kanji.json");

Loading…
Cancel
Save