From ddc29b89d7db863f2e6fdfd3f6be6c8ae2733bfa Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Tue, 2 Oct 2018 09:03:50 +0000 Subject: [PATCH] Simplified some local numeric variable types in Rust code. --- rust/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index bb57352..89a9a60 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -641,10 +641,10 @@ impl QrCode { // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8. // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table. fn get_num_raw_data_modules(ver: Version) -> usize { - let ver = ver.value(); - let mut result: usize = (16 * (ver as usize) + 128) * (ver as usize) + 64; + let ver = ver.value() as usize; + let mut result: usize = (16 * ver + 128) * ver + 64; if ver >= 2 { - let numalign: usize = (ver as usize) / 7 + 2; + let numalign: usize = ver / 7 + 2; result -= (25 * numalign - 10) * numalign - 55; if ver >= 7 { result -= 36; @@ -858,7 +858,7 @@ impl QrSegment { pub fn make_numeric(text: &[char]) -> Self { let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + (text.len() + 2) / 3)); let mut accumdata: u32 = 0; - let mut accumcount: u32 = 0; + let mut accumcount: u8 = 0; for c in text { assert!('0' <= *c && *c <= '9', "String contains non-numeric characters"); accumdata = accumdata * 10 + ((*c as u32) - ('0' as u32)); @@ -870,7 +870,7 @@ impl QrSegment { } } if accumcount > 0 { // 1 or 2 digits remaining - bb.append_bits(accumdata, (accumcount as u8) * 3 + 1); + bb.append_bits(accumdata, accumcount * 3 + 1); } QrSegment::new(QrSegmentMode::Numeric, text.len(), bb.0) }