From 1424d9f3320f2755dc8c2014f52959354cd6c87b Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sat, 10 Aug 2019 02:36:56 +0000 Subject: [PATCH] Simplified a bit of TypeScript and Rust code using for-each looping. --- rust/src/lib.rs | 4 ++-- typescript-javascript/qrcodegen.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index eef02d1..147b542 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -567,10 +567,10 @@ impl QrCode { // Interleave (not concatenate) the bytes from every block into a single sequence let mut result = Vec::::with_capacity(rawcodewords); for i in 0 .. shortblocklen + 1 { - for j in 0 .. numblocks { + for (j, block) in blocks.iter().enumerate() { // Skip the padding byte in short blocks if i != shortblocklen - blockecclen || j >= numshortblocks { - result.push(blocks[j][i]); + result.push(block[i]); } } } diff --git a/typescript-javascript/qrcodegen.ts b/typescript-javascript/qrcodegen.ts index a7f0ab4..00e7827 100644 --- a/typescript-javascript/qrcodegen.ts +++ b/typescript-javascript/qrcodegen.ts @@ -435,11 +435,11 @@ namespace qrcodegen { // Interleave (not concatenate) the bytes from every block into a single sequence let result: Array = []; for (let i = 0; i < blocks[0].length; i++) { - for (let j = 0; j < blocks.length; j++) { + blocks.forEach((block, j) => { // Skip the padding byte in short blocks if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) - result.push(blocks[j][i]); - } + result.push(block[i]); + }); } if (result.length != rawCodewords) throw "Assertion error";