Simplified a bit of TypeScript and Rust code using for-each looping.

This commit is contained in:
Project Nayuki 2019-08-10 02:36:56 +00:00
parent 7eac8beffe
commit 1424d9f332
2 changed files with 5 additions and 5 deletions

View File

@ -567,10 +567,10 @@ impl QrCode {
// Interleave (not concatenate) the bytes from every block into a single sequence // Interleave (not concatenate) the bytes from every block into a single sequence
let mut result = Vec::<u8>::with_capacity(rawcodewords); let mut result = Vec::<u8>::with_capacity(rawcodewords);
for i in 0 .. shortblocklen + 1 { 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 // Skip the padding byte in short blocks
if i != shortblocklen - blockecclen || j >= numshortblocks { if i != shortblocklen - blockecclen || j >= numshortblocks {
result.push(blocks[j][i]); result.push(block[i]);
} }
} }
} }

View File

@ -435,11 +435,11 @@ namespace qrcodegen {
// Interleave (not concatenate) the bytes from every block into a single sequence // Interleave (not concatenate) the bytes from every block into a single sequence
let result: Array<byte> = []; let result: Array<byte> = [];
for (let i = 0; i < blocks[0].length; i++) { 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 // Skip the padding byte in short blocks
if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
result.push(blocks[j][i]); result.push(block[i]);
} });
} }
if (result.length != rawCodewords) if (result.length != rawCodewords)
throw "Assertion error"; throw "Assertion error";