Simplified an analogous piece of C++ and Rust code.

This commit is contained in:
Project Nayuki 2017-08-28 00:54:44 +00:00
parent eb200b8ebc
commit 5ddb2e9d63
2 changed files with 7 additions and 8 deletions

View File

@ -81,10 +81,9 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, const Ecc &ecl,
// Increase the error correction level while the data still fits in the current version number // Increase the error correction level while the data still fits in the current version number
const Ecc *newEcl = &ecl; const Ecc *newEcl = &ecl;
if (boostEcl) { for (const Ecc *anEcl : vector<const Ecc*>{&Ecc::MEDIUM, &Ecc::QUARTILE, &Ecc::HIGH}) {
if (dataUsedBits <= getNumDataCodewords(version, Ecc::MEDIUM ) * 8) newEcl = &Ecc::MEDIUM ; if (boostEcl && dataUsedBits <= getNumDataCodewords(version, *anEcl) * 8)
if (dataUsedBits <= getNumDataCodewords(version, Ecc::QUARTILE) * 8) newEcl = &Ecc::QUARTILE; newEcl = anEcl;
if (dataUsedBits <= getNumDataCodewords(version, Ecc::HIGH ) * 8) newEcl = &Ecc::HIGH ;
} }
// Create the data bit string by concatenating all segments // Create the data bit string by concatenating all segments

View File

@ -92,10 +92,10 @@ impl QrCode {
} }
// Increase the error correction level while the data still fits in the current version number // Increase the error correction level while the data still fits in the current version number
if boostecl { for newecl in &[&QrCodeEcc_MEDIUM, &QrCodeEcc_QUARTILE, &QrCodeEcc_HIGH] {
if datausedbits <= QrCode::get_num_data_codewords(version, &QrCodeEcc_MEDIUM ) * 8 { ecl = &QrCodeEcc_MEDIUM ; } if boostecl && datausedbits <= QrCode::get_num_data_codewords(version, newecl) * 8 {
if datausedbits <= QrCode::get_num_data_codewords(version, &QrCodeEcc_QUARTILE) * 8 { ecl = &QrCodeEcc_QUARTILE; } ecl = newecl;
if datausedbits <= QrCode::get_num_data_codewords(version, &QrCodeEcc_HIGH ) * 8 { ecl = &QrCodeEcc_HIGH ; } }
} }
// Create the data bit string by concatenating all segments // Create the data bit string by concatenating all segments