diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 7b1a537..3c5bc29 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -368,8 +368,7 @@ class QrCode(object): ecc = rs.get_remainder(dat) if i < numshortblocks: dat.append(0) - dat.extend(ecc) - blocks.append(dat) + blocks.append(dat + ecc) assert k == len(data) # Interleave (not concatenate) the bytes from every block into a single sequence diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c4f5f59..ce68e6f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -240,7 +240,7 @@ impl QrCode { // Note that Unix newlines (\n) are always used, regardless of the platform. pub fn to_svg_string(&self, border: i32) -> String { assert!(border >= 0, "Border must be non-negative"); - let mut result: String = String::new(); + let mut result = String::new(); result += "\n"; result += "\n"; let dimension = self.size.checked_add(border.checked_mul(2).unwrap()).unwrap(); @@ -308,7 +308,7 @@ impl QrCode { // Calculate error correction code and pack bits let size: i32 = self.size; // errcorrlvl is uint2, mask is uint3 - let mut data: u32 = self.errorcorrectionlevel.format_bits() << 3 | (mask.value() as u32); + let data: u32 = self.errorcorrectionlevel.format_bits() << 3 | (mask.value() as u32); let mut rem: u32 = data; for _ in 0 .. 10 { rem = (rem << 1) ^ ((rem >> 9) * 0x537); @@ -420,8 +420,7 @@ impl QrCode { let rs = ReedSolomonGenerator::new(blockecclen); let mut k: usize = 0; for i in 0 .. numblocks { - let mut dat = Vec::::with_capacity(shortblocklen + 1); - dat.extend_from_slice(&data[k .. k + shortblocklen - blockecclen + ((i >= numshortblocks) as usize)]); + let mut dat = data[k .. k + shortblocklen - blockecclen + ((i >= numshortblocks) as usize)].to_vec(); k += dat.len(); let ecc: Vec = rs.get_remainder(&dat); if i < numshortblocks { diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 081cea1..a31605a 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -286,11 +286,11 @@ namespace qrcodegen { // based on the given mask and this object's error correction level field. private drawFormatBits(mask: int): void { // Calculate error correction code and pack bits - let data: int = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3 + const data: int = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3 let rem: int = data; for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); - let bits = (data << 10 | rem) ^ 0x5412; // uint15 + const bits = (data << 10 | rem) ^ 0x5412; // uint15 if (bits >>> 15 != 0) throw "Assertion error"; @@ -322,7 +322,7 @@ namespace qrcodegen { let rem: int = this.version; // version is uint6, in the range [7, 40] for (let i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25); - let bits: int = this.version << 12 | rem; // uint18 + const bits: int = this.version << 12 | rem; // uint18 if (bits >>> 18 != 0) throw "Assertion error";