From cf47d8a8263673a7c143aa435d9d3d3b38f28c82 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 11 Jan 2024 17:39:27 -0600 Subject: [PATCH] perf: QRCode: skip extra version check ported from: https://github.com/zxing-cpp/zxing-cpp/commit/ac88bce74311fdbf376faf0bc88e90d0990d048a The version bits have already been parsed during detection. If they would have been wrong then, we would not have ended up here. If we did, there is no point in reading them again. --- src/qrcode/cpp_port/bitmatrix_parser.rs | 34 +++---------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/qrcode/cpp_port/bitmatrix_parser.rs b/src/qrcode/cpp_port/bitmatrix_parser.rs index 957f35c..393f021 100644 --- a/src/qrcode/cpp_port/bitmatrix_parser.rs +++ b/src/qrcode/cpp_port/bitmatrix_parser.rs @@ -29,38 +29,10 @@ pub fn ReadVersion(bitMatrix: &BitMatrix, qr_type: Type) -> Result { let number = Version::Number(bitMatrix); match qr_type { - Type::Model1 => return Version::Model1(number), - - Type::Micro => return Version::Micro(number), - Type::Model2 => {} + Type::Model1 => Version::Model1(number), + Type::Micro => Version::Micro(number), + Type::Model2 => Version::Model2(number), } - let mut version = Version::Model2(number)?; - - if version.getVersionNumber() < 7 { - return Ok(version); - } - - let dimension = bitMatrix.height(); - - for mirror in [false, true] { - // for (bool mirror : {false, true}) { - // Read top-right/bottom-left version info: 3 wide by 6 tall (depending on mirrored) - let mut versionBits = 0; - for y in (0..=5).rev() { - // for (int y = 5; y >= 0; --y) { - for x in ((dimension - 11)..=(dimension - 9)).rev() { - // for (int x = dimension - 9; x >= dimension - 11; --x) { - AppendBit(&mut versionBits, getBit(bitMatrix, x, y, Some(mirror))); - } - } - - version = Version::DecodeVersionInformation(versionBits, 0)?; // THIS MIGHT BE WRONG todo!() - if version.getDimensionForVersion() == dimension { - return Ok(version); - } - } - - Err(Exceptions::FORMAT) } pub fn ReadFormatInformation(bitMatrix: &BitMatrix) -> Result {