perf: code cleanup and loop fixes

This commit is contained in:
Henry Schimke
2024-02-09 10:22:38 -06:00
parent 44d7853099
commit b57d7e35fa
19 changed files with 120 additions and 188 deletions

View File

@@ -42,12 +42,11 @@ pub struct BitArray {
impl BitArray { impl BitArray {
pub fn new() -> Self { pub fn new() -> Self {
// Self { Self {
// bits: Vec::new(), bits: Vec::new(),
// size: 0, size: 0,
// read_offset: 0, read_offset: 0,
// } }
Self::default()
} }
pub fn with_size(size: usize) -> Self { pub fn with_size(size: usize) -> Self {

View File

@@ -18,8 +18,6 @@ use unicode_segmentation::UnicodeSegmentation;
use super::{CharacterSet, Eci}; use super::{CharacterSet, Eci};
use once_cell::sync::Lazy;
// static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| { // static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| {
// let mut enc_vec = Vec::new(); // let mut enc_vec = Vec::new();
// for name in NAMES { // for name in NAMES {
@@ -53,30 +51,28 @@ use once_cell::sync::Lazy;
// "Shift_JIS", // "Shift_JIS",
// ]; // ];
static ENCODERS: Lazy<Vec<CharacterSet>> = Lazy::new(|| { const ENCODERS: [CharacterSet; 14] = [
vec![ CharacterSet::Cp437,
CharacterSet::Cp437, CharacterSet::ISO8859_2,
CharacterSet::ISO8859_2, CharacterSet::ISO8859_3,
CharacterSet::ISO8859_3, CharacterSet::ISO8859_4,
CharacterSet::ISO8859_4, CharacterSet::ISO8859_5,
CharacterSet::ISO8859_5, // CharacterSet::ISO8859_6,
// CharacterSet::ISO8859_6, CharacterSet::ISO8859_7,
CharacterSet::ISO8859_7, // CharacterSet::ISO8859_8,
// CharacterSet::ISO8859_8, CharacterSet::ISO8859_9,
CharacterSet::ISO8859_9, // CharacterSet::ISO8859_10,
// CharacterSet::ISO8859_10, // CharacterSet::ISO8859_11,
// CharacterSet::ISO8859_11, // CharacterSet::ISO8859_13,
// CharacterSet::ISO8859_13, // CharacterSet::ISO8859_14,
// CharacterSet::ISO8859_14, CharacterSet::ISO8859_15,
CharacterSet::ISO8859_15, CharacterSet::ISO8859_16,
CharacterSet::ISO8859_16, CharacterSet::Shift_JIS,
CharacterSet::Shift_JIS, CharacterSet::Cp1250,
CharacterSet::Cp1250, CharacterSet::Cp1251,
CharacterSet::Cp1251, CharacterSet::Cp1252,
CharacterSet::Cp1252, CharacterSet::Cp1256,
CharacterSet::Cp1256, ];
]
});
/** /**
* Set of CharsetEncoders for a given input string * Set of CharsetEncoders for a given input string
@@ -144,10 +140,7 @@ impl ECIEncoderSet {
} }
if !canEncode { if !canEncode {
//for the character at position i we don't yet have an encoder in the list //for the character at position i we don't yet have an encoder in the list
for i_encoder in 0..ENCODERS.len() { for encoder in ENCODERS.iter() {
// for encoder in ENCODERS {
let encoder = ENCODERS.get(i_encoder).unwrap();
// for (CharsetEncoder encoder : ENCODERS) {
if encoder.encode(stringToEncode.get(i).unwrap()).is_ok() { if encoder.encode(stringToEncode.get(i).unwrap()).is_ok() {
//Good, we found an encoder that can encode the character. We add him to the list and continue scanning //Good, we found an encoder that can encode the character. We add him to the list and continue scanning
//the input //the input
@@ -172,33 +165,18 @@ impl ECIEncoderSet {
// we need more than one single byte encoder or we need a Unicode encoder. // we need more than one single byte encoder or we need a Unicode encoder.
// In this case we append a UTF-8 and UTF-16 encoder to the list // In this case we append a UTF-8 and UTF-16 encoder to the list
// encoders = [] new CharsetEncoder[neededEncoders.size() + 2]; // encoders = [] new CharsetEncoder[neededEncoders.size() + 2];
encoders = Vec::new(); encoders = Vec::with_capacity(neededEncoders.len() + 2);
// let index = 0;
for encoder in neededEncoders { encoders.extend(neededEncoders);
// for (CharsetEncoder encoder : neededEncoders) {
//encoders[index++] = encoder;
encoders.push(encoder);
}
encoders.push(CharacterSet::UTF8); encoders.push(CharacterSet::UTF8);
encoders.push(CharacterSet::UTF16BE); encoders.push(CharacterSet::UTF16BE);
} }
//Compute priorityEncoderIndex by looking up priorityCharset in encoders //Compute priorityEncoderIndex by looking up priorityCharset in encoders
// if priorityCharset != null { if let Some(pc) = priorityCharset.as_ref() {
if priorityCharset.is_some() { priorityEncoderIndexValue = encoders.iter().position(|enc| enc == pc);
// for i in 0..encoders.len() {
for (i, encoder) in encoders.iter().enumerate() {
// for (int i = 0; i < encoders.length; i++) {
// if priorityCharset.as_ref().unwrap().name() == encoder.name() {
if priorityCharset.as_ref().unwrap() == encoder {
priorityEncoderIndexValue = Some(i);
break;
}
}
} }
// }
//invariants //invariants
assert_eq!(encoders[0], CharacterSet::ISO8859_1); assert_eq!(encoders[0], CharacterSet::ISO8859_1);
Self { Self {

View File

@@ -206,9 +206,6 @@ impl MinimalECIInput {
.zip(&stringToEncode) .zip(&stringToEncode)
.take(stringToEncode.len()) .take(stringToEncode.len())
{ {
// for i in 0..stringToEncode.len() {
// for (int i = 0; i < bytes.length; i++) {
// let c = stringToEncode.get(i).unwrap();
*byt = if fnc1.is_some() && c == fnc1.as_ref().unwrap() { *byt = if fnc1.is_some() && c == fnc1.as_ref().unwrap() {
1000 1000
} else { } else {
@@ -332,17 +329,12 @@ impl MinimalECIInput {
} }
} }
//optimize memory by removing edges that have been passed. //optimize memory by removing edges that have been passed.
for j in 0..encoderSet.len() { edges[i - 1][..encoderSet.len()].fill(None);
// for (int j = 0; j < encoderSet.length(); j++) {
edges[i - 1][j] = None;
}
} }
let mut minimalJ: i32 = -1; let mut minimalJ: i32 = -1;
let mut minimalSize: i32 = i32::MAX; let mut minimalSize: i32 = i32::MAX;
for j in 0..encoderSet.len() { for j in 0..encoderSet.len() {
// for (int j = 0; j < encoderSet.length(); j++) { if let Some(edge) = edges[inputLength][j].clone() {
if edges[inputLength][j].is_some() {
let edge = edges[inputLength][j].clone().unwrap();
if (edge.cachedTotalSize as i32) < minimalSize { if (edge.cachedTotalSize as i32) < minimalSize {
minimalSize = edge.cachedTotalSize as i32; minimalSize = edge.cachedTotalSize as i32;
minimalJ = j as i32; minimalJ = j as i32;
@@ -379,20 +371,11 @@ impl MinimalECIInput {
c.previous.clone().unwrap().encoderIndex c.previous.clone().unwrap().encoderIndex
}; };
if previousEncoderIndex != c.encoderIndex { if previousEncoderIndex != c.encoderIndex {
// intsAL.splice(
// 0..0,
// [256 as u16 + encoderSet.getECIValue(c.encoderIndex) as u16],
// );
intsAL.insert(0, 256_u16 + encoderSet.get_eci(c.encoderIndex) as u16); intsAL.insert(0, 256_u16 + encoderSet.get_eci(c.encoderIndex) as u16);
} }
current = c.previous.clone(); current = c.previous.clone();
} }
//let mut ints = vec![0; intsAL.len()];
// for i in 0..ints.len() {
// // for (int i = 0; i < ints.length; i++) {
// ints[i] = *intsAL.get(i).unwrap();
// }
//ints[..].copy_from_slice(&intsAL[..]);
intsAL intsAL
} }
} }

View File

@@ -38,7 +38,7 @@ impl Quadrilateral {
pub fn orientation(&self) -> f64 { pub fn orientation(&self) -> f64 {
let centerLine = let centerLine =
(*self.top_right() + *self.bottom_right()) - (*self.top_left() + *self.bottom_left()); (*self.top_right() + *self.bottom_right()) - (*self.top_left() + *self.bottom_left());
if (centerLine == Point { x: 0.0, y: 0.0 }) { if centerLine == Point::default() {
return 0.0; return 0.0;
} }
let centerLineF = Point::normalized(centerLine); let centerLineF = Point::normalized(centerLine);

View File

@@ -89,9 +89,10 @@ impl ReedSolomonDecoder {
let omega = &sigmaOmega[1]; let omega = &sigmaOmega[1];
let errorLocations = self.findErrorLocations(sigma)?; let errorLocations = self.findErrorLocations(sigma)?;
let errorMagnitudes = self.findErrorMagnitudes(omega, &errorLocations)?; let errorMagnitudes = self.findErrorMagnitudes(omega, &errorLocations)?;
for i in 0..errorLocations.len() { for (error_location, error_magnitude) in errorLocations.iter().zip(errorMagnitudes) {
// for i in 0..errorLocations.len() {
//for (int i = 0; i < errorLocations.length; i++) { //for (int i = 0; i < errorLocations.length; i++) {
let log_value = self.field.log(errorLocations[i] as i32)?; let log_value = self.field.log(*error_location as i32)?;
if log_value > received.len() as i32 - 1 { if log_value > received.len() as i32 - 1 {
return Err(Exceptions::reed_solomon_with("Bad error location")); return Err(Exceptions::reed_solomon_with("Bad error location"));
} }
@@ -100,7 +101,7 @@ impl ReedSolomonDecoder {
return Err(Exceptions::reed_solomon_with("Bad error location")); return Err(Exceptions::reed_solomon_with("Bad error location"));
} }
received[position as usize] = received[position as usize] =
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]); GenericGF::addOrSubtract(received[position as usize], error_magnitude);
} }
Ok(errorLocations.len()) Ok(errorLocations.len())
} }
@@ -164,9 +165,8 @@ impl ReedSolomonDecoder {
return Err(Exceptions::reed_solomon_with("sigmaTilde(0) was zero")); return Err(Exceptions::reed_solomon_with("sigmaTilde(0) was zero"));
} }
let inverse = match self.field.inverse(sigmaTildeAtZero) { let Ok(inverse) = self.field.inverse(sigmaTildeAtZero) else {
Ok(res) => res, return Err(Exceptions::reed_solomon_with("ArithmetricException"));
Err(_err) => return Err(Exceptions::reed_solomon_with("ArithmetricException")),
}; };
let sigma = t.multiply_with_scalar(inverse); let sigma = t.multiply_with_scalar(inverse);
let omega = r.multiply_with_scalar(inverse); let omega = r.multiply_with_scalar(inverse);

View File

@@ -108,15 +108,10 @@ pub fn guessCharset(bytes: &[u8], hints: &DecodingHintDictionary) -> Option<Char
// for i in 0..length { // for i in 0..length {
for value in bytes.iter().take(length).copied() { for value in bytes.iter().take(length).copied() {
// for (int i = 0;
// i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8);
// i++) {
if !(can_be_iso88591 || can_be_shift_jis || can_be_utf8) { if !(can_be_iso88591 || can_be_shift_jis || can_be_utf8) {
break; break;
} }
// let value = bytes[i];
// UTF-8 stuff // UTF-8 stuff
if can_be_utf8 { if can_be_utf8 {
if utf8_bytes_left > 0 { if utf8_bytes_left > 0 {

View File

@@ -26,6 +26,7 @@ use super::Version;
* *
* @author bbrown@google.com (Brian Brown) * @author bbrown@google.com (Brian Brown)
*/ */
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataBlock { pub struct DataBlock {
numDataCodewords: u32, numDataCodewords: u32,
codewords: Vec<u8>, codewords: Vec<u8>,
@@ -65,19 +66,18 @@ impl DataBlock {
// Now establish DataBlocks of the appropriate size and number of data codewords // Now establish DataBlocks of the appropriate size and number of data codewords
let mut result = Vec::with_capacity(totalBlocks); let mut result = Vec::with_capacity(totalBlocks);
let mut numRXingResultBlocks = 0; let mut numRXingResultBlocks: usize = 0;
for ecBlock in ecBlockArray { for ecBlock in ecBlockArray {
for _i in 0..ecBlock.getCount() { let numDataCodewords = ecBlock.getDataCodewords() as usize;
// for (int i = 0; i < ecBlock.getCount(); i++) { let numBlockCodewords = ecBlocks.getECCodewords() as usize + numDataCodewords;
let numDataCodewords = ecBlock.getDataCodewords() as usize; result.extend(vec![
let numBlockCodewords = ecBlocks.getECCodewords() as usize + numDataCodewords; DataBlock::new(
// result[numRXingResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
result.push(DataBlock::new(
numDataCodewords as u32, numDataCodewords as u32,
vec![0; numBlockCodewords], vec![0; numBlockCodewords]
)); );
numRXingResultBlocks += 1; ecBlock.getCount() as usize
} ]);
numRXingResultBlocks += ecBlock.getCount() as usize;
} }
// All blocks have the same amount of data, except that the last n // All blocks have the same amount of data, except that the last n

View File

@@ -100,12 +100,14 @@ impl<'a> Detector<'_> {
)) ))
} }
#[inline]
fn shiftPoint(p: Point, to: Point, div: u32) -> Point { fn shiftPoint(p: Point, to: Point, div: u32) -> Point {
let x = (to.x - p.x) / (div as f32 + 1.0); let x = (to.x - p.x) / (div as f32 + 1.0);
let y = (to.y - p.y) / (div as f32 + 1.0); let y = (to.y - p.y) / (div as f32 + 1.0);
point_f(p.x + x, p.y + y) point_f(p.x + x, p.y + y)
} }
#[inline]
fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point { fn moveAway(p: Point, fromX: f32, fromY: f32) -> Point {
let mut x = p.x; let mut x = p.x;
let mut y = p.y; let mut y = p.y;
@@ -177,10 +179,7 @@ impl<'a> Detector<'_> {
// A..D // A..D
// : : // : :
// B--C // B--C
let pointA = points[0]; let [pointA, pointB, pointC, pointD] = points;
let pointB = points[1];
let pointC = points[2];
let pointD = points[3];
// Transition detection on the edge is not stable. // Transition detection on the edge is not stable.
// To safely detect, shift the points to the module center. // To safely detect, shift the points to the module center.
@@ -269,10 +268,7 @@ impl<'a> Detector<'_> {
// A..D // A..D
// | : // | :
// B--C // B--C
let mut pointA = points[0]; let [mut pointA, mut pointB, mut pointC, mut pointD] = points;
let mut pointB = points[1];
let mut pointC = points[2];
let mut pointD = points[3];
// calculate pseudo dimensions // calculate pseudo dimensions
let mut dimH = self.transitionsBetween(pointA, pointD) + 1; let mut dimH = self.transitionsBetween(pointA, pointD) + 1;
@@ -317,6 +313,7 @@ impl<'a> Detector<'_> {
[pointAs, pointBs, pointCs, pointDs] [pointAs, pointBs, pointCs, pointDs]
} }
#[inline]
fn isValid(&self, p: Point) -> bool { fn isValid(&self, p: Point) -> bool {
p.x >= 0.0 p.x >= 0.0
&& p.x <= self.image.getWidth() as f32 - 1.0 && p.x <= self.image.getWidth() as f32 - 1.0

View File

@@ -54,9 +54,7 @@ fn Scan(
let mut br = Point::default(); let mut br = Point::default();
let mut tr = Point::default(); let mut tr = Point::default();
for l in lines.iter_mut() { lines.iter_mut().for_each(|l| l.reset());
l.reset();
}
let [lineL, lineB, lineR, lineT] = lines; let [lineL, lineB, lineR, lineT] = lines;

View File

@@ -19,6 +19,7 @@ use crate::Exceptions;
use super::{high_level_encoder, Encoder}; use super::{high_level_encoder, Encoder};
#[derive(Debug, Default)]
pub struct ASCIIEncoder; pub struct ASCIIEncoder;
impl Encoder for ASCIIEncoder { impl Encoder for ASCIIEncoder {
@@ -111,8 +112,3 @@ impl ASCIIEncoder {
} }
} }
} }
impl Default for ASCIIEncoder {
fn default() -> Self {
Self::new()
}
}

View File

@@ -22,7 +22,9 @@ use super::{
Encoder, Encoder,
}; };
#[derive(Debug, Default)]
pub struct Base256Encoder; pub struct Base256Encoder;
impl Encoder for Base256Encoder { impl Encoder for Base256Encoder {
fn getEncodingMode(&self) -> usize { fn getEncodingMode(&self) -> usize {
BASE256_ENCODATION BASE256_ENCODATION
@@ -109,7 +111,7 @@ impl Base256Encoder {
pub fn new() -> Self { pub fn new() -> Self {
Self Self
} }
fn randomize255State(ch: char, codewordPosition: u32) -> Option<char> { const fn randomize255State(ch: char, codewordPosition: u32) -> Option<char> {
let pseudoRandom = ((149 * codewordPosition) % 255) + 1; let pseudoRandom = ((149 * codewordPosition) % 255) + 1;
let tempVariable = ch as u32 + pseudoRandom; let tempVariable = ch as u32 + pseudoRandom;
if tempVariable <= 255 { if tempVariable <= 255 {
@@ -119,9 +121,3 @@ impl Base256Encoder {
} }
} }
} }
impl Default for Base256Encoder {
fn default() -> Self {
Self::new()
}
}

View File

@@ -23,6 +23,7 @@ use super::high_level_encoder::{
use super::{Encoder, EncoderContext}; use super::{Encoder, EncoderContext};
#[derive(Debug, Default)]
pub struct C40Encoder; pub struct C40Encoder;
impl Encoder for C40Encoder { impl Encoder for C40Encoder {
@@ -301,9 +302,3 @@ impl C40Encoder {
// return new String(new char[] {cw1, cw2}); // return new String(new char[] {cw1, cw2});
} }
} }
impl Default for C40Encoder {
fn default() -> Self {
Self::new()
}
}

View File

@@ -19,6 +19,7 @@ use crate::Exceptions;
use super::{high_level_encoder, Encoder, EncoderContext}; use super::{high_level_encoder, Encoder, EncoderContext};
#[derive(Debug, Default)]
pub struct EdifactEncoder; pub struct EdifactEncoder;
impl Encoder for EdifactEncoder { impl Encoder for EdifactEncoder {
fn getEncodingMode(&self) -> usize { fn getEncodingMode(&self) -> usize {
@@ -185,9 +186,3 @@ impl EdifactEncoder {
Ok(res) Ok(res)
} }
} }
impl Default for EdifactEncoder {
fn default() -> Self {
Self::new()
}
}

View File

@@ -548,10 +548,12 @@ fn getMinimumCount(mins: &[u8]) -> u32 {
mins.iter().take(6).sum::<u8>() as u32 mins.iter().take(6).sum::<u8>() as u32
} }
pub fn isDigit(ch: char) -> bool { #[inline]
pub const fn isDigit(ch: char) -> bool {
ch.is_ascii_digit() ch.is_ascii_digit()
} }
#[inline]
pub fn isExtendedASCII(ch: char) -> bool { pub fn isExtendedASCII(ch: char) -> bool {
(ch as u8) >= 128 //&& (ch as u8) <= 255 (ch as u8) >= 128 //&& (ch as u8) <= 255
} }

View File

@@ -99,6 +99,7 @@ pub fn isExtendedASCII(ch: char, fnc1: Option<char>) -> bool {
// return ch != fnc1 && ch as u8 >= 128 && ch as u8 <= 255; // return ch != fnc1 && ch as u8 >= 128 && ch as u8 <= 255;
} }
#[inline]
fn isInC40Shift1Set(ch: char) -> bool { fn isInC40Shift1Set(ch: char) -> bool {
ch as u8 <= 31 ch as u8 <= 31
} }
@@ -606,16 +607,15 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult> {
} }
} }
//optimize memory by removing edges that have been passed. //optimize memory by removing edges that have been passed.
for j in 0..6 { edges[i - 1][..6].fill(None);
edges[i - 1][j] = None;
}
} }
let mut minimalJ: i32 = -1; let mut minimalJ: i32 = -1;
let mut minimalSize = i32::MAX; let mut minimalSize = i32::MAX;
for j in 0..6 { for j in 0..6 {
if edges[inputLength][j].is_some() { if let Some(edge) = &edges[inputLength][j] {
let edge = edges[inputLength][j].as_ref().unwrap(); // if edges[inputLength][j].is_some() {
// let edge = edges[inputLength][j].as_ref().unwrap();
let size = if (1..=3).contains(&j) { let size = if (1..=3).contains(&j) {
edge.cachedTotalSize + 1 edge.cachedTotalSize + 1
} else { } else {
@@ -955,6 +955,7 @@ impl Edge {
Self::getMinSymbolSize(self, minimum) - minimum Self::getMinSymbolSize(self, minimum) - minimum
} }
#[inline]
pub fn getBytes1(c: u32) -> Vec<u8> { pub fn getBytes1(c: u32) -> Vec<u8> {
// let result = vec![0u8;1]; // let result = vec![0u8;1];
// result[0] = c as u8; // result[0] = c as u8;
@@ -962,6 +963,7 @@ impl Edge {
vec![c as u8] vec![c as u8]
} }
#[inline]
pub fn getBytes2(c1: u32, c2: u32) -> Vec<u8> { pub fn getBytes2(c1: u32, c2: u32) -> Vec<u8> {
// byte[] result = new byte[2]; // byte[] result = new byte[2];
// result[0] = (byte) c1; // result[0] = (byte) c1;
@@ -1347,13 +1349,13 @@ impl RXingResult {
} }
pub fn prepend(bytes: &[u8], into: &mut Vec<u8>) -> usize { pub fn prepend(bytes: &[u8], into: &mut Vec<u8>) -> usize {
for i in (0..bytes.len()).rev() { for byte in bytes.iter().rev() {
// for (int i = bytes.length - 1; i >= 0; i--) { into.insert(0, *byte);
into.insert(0, bytes[i]);
} }
bytes.len() bytes.len()
} }
#[inline]
fn randomize253State(codewordPosition: u32) -> u32 { fn randomize253State(codewordPosition: u32) -> u32 {
let pseudoRandom = ((149 * codewordPosition) % 253) + 1; let pseudoRandom = ((149 * codewordPosition) % 253) + 1;
let tempVariable = 129 + pseudoRandom; let tempVariable = 129 + pseudoRandom;

View File

@@ -20,42 +20,39 @@ use crate::common::Result;
use crate::{Dimension, Exceptions}; use crate::{Dimension, Exceptions};
use super::SymbolShapeHint; use super::SymbolShapeHint;
use once_cell::sync::Lazy;
pub(super) static PROD_SYMBOLS: Lazy<Vec<SymbolInfo>> = Lazy::new(|| { pub(super) const PROD_SYMBOLS: [SymbolInfo; 30] = [
vec![ SymbolInfo::new(false, 3, 5, 8, 8, 1),
SymbolInfo::new(false, 3, 5, 8, 8, 1), SymbolInfo::new(false, 5, 7, 10, 10, 1),
SymbolInfo::new(false, 5, 7, 10, 10, 1), /*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1),
/*rect*/ SymbolInfo::new(true, 5, 7, 16, 6, 1), SymbolInfo::new(false, 8, 10, 12, 12, 1),
SymbolInfo::new(false, 8, 10, 12, 12, 1), /*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2),
/*rect*/ SymbolInfo::new(true, 10, 11, 14, 6, 2), SymbolInfo::new(false, 12, 12, 14, 14, 1),
SymbolInfo::new(false, 12, 12, 14, 14, 1), /*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1),
/*rect*/ SymbolInfo::new(true, 16, 14, 24, 10, 1), SymbolInfo::new(false, 18, 14, 16, 16, 1),
SymbolInfo::new(false, 18, 14, 16, 16, 1), SymbolInfo::new(false, 22, 18, 18, 18, 1),
SymbolInfo::new(false, 22, 18, 18, 18, 1), /*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2),
/*rect*/ SymbolInfo::new(true, 22, 18, 16, 10, 2), SymbolInfo::new(false, 30, 20, 20, 20, 1),
SymbolInfo::new(false, 30, 20, 20, 20, 1), /*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2),
/*rect*/ SymbolInfo::new(true, 32, 24, 16, 14, 2), SymbolInfo::new(false, 36, 24, 22, 22, 1),
SymbolInfo::new(false, 36, 24, 22, 22, 1), SymbolInfo::new(false, 44, 28, 24, 24, 1),
SymbolInfo::new(false, 44, 28, 24, 24, 1), /*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2),
/*rect*/ SymbolInfo::new(true, 49, 28, 22, 14, 2), SymbolInfo::new(false, 62, 36, 14, 14, 4),
SymbolInfo::new(false, 62, 36, 14, 14, 4), SymbolInfo::new(false, 86, 42, 16, 16, 4),
SymbolInfo::new(false, 86, 42, 16, 16, 4), SymbolInfo::new(false, 114, 48, 18, 18, 4),
SymbolInfo::new(false, 114, 48, 18, 18, 4), SymbolInfo::new(false, 144, 56, 20, 20, 4),
SymbolInfo::new(false, 144, 56, 20, 20, 4), SymbolInfo::new(false, 174, 68, 22, 22, 4),
SymbolInfo::new(false, 174, 68, 22, 22, 4), SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42),
SymbolInfo::with_details(false, 204, 84, 24, 24, 4, 102, 42), SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56),
SymbolInfo::with_details(false, 280, 112, 14, 14, 16, 140, 56), SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36),
SymbolInfo::with_details(false, 368, 144, 16, 16, 16, 92, 36), SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48),
SymbolInfo::with_details(false, 456, 192, 18, 18, 16, 114, 48), SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56),
SymbolInfo::with_details(false, 576, 224, 20, 20, 16, 144, 56), SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68),
SymbolInfo::with_details(false, 696, 272, 22, 22, 16, 174, 68), SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56),
SymbolInfo::with_details(false, 816, 336, 24, 24, 16, 136, 56), SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68),
SymbolInfo::with_details(false, 1050, 408, 18, 18, 36, 175, 68), SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62),
SymbolInfo::with_details(false, 1304, 496, 20, 20, 36, 163, 62), SymbolInfo::new_symbol_info_144(),
SymbolInfo::new_symbol_info_144(), ];
]
});
/** /**
* Symbol info table for DataMatrix. * Symbol info table for DataMatrix.
@@ -74,7 +71,7 @@ pub struct SymbolInfo {
isSymbolInfo144: bool, isSymbolInfo144: bool,
} }
impl SymbolInfo { impl SymbolInfo {
pub fn new( pub const fn new(
rectangular: bool, rectangular: bool,
dataCapacity: u32, dataCapacity: u32,
errorCodewords: u32, errorCodewords: u32,
@@ -95,7 +92,7 @@ impl SymbolInfo {
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn with_details( pub const fn with_details(
rectangular: bool, rectangular: bool,
dataCapacity: u32, dataCapacity: u32,
errorCodewords: u32, errorCodewords: u32,
@@ -117,7 +114,7 @@ impl SymbolInfo {
isSymbolInfo144: false, isSymbolInfo144: false,
} }
} }
pub fn new_symbol_info_144() -> Self { pub const fn new_symbol_info_144() -> Self {
let mut new_symbol = Self::with_details(false, 1558, 620, 22, 22, 36, -1, 62); let mut new_symbol = Self::with_details(false, 1558, 620, 22, 22, 36, -1, 62);
new_symbol.isSymbolInfo144 = true; new_symbol.isSymbolInfo144 = true;
new_symbol new_symbol
@@ -223,7 +220,7 @@ impl fmt::Display for SymbolInfo {
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct SymbolInfoLookup<'a>(Option<&'a Vec<SymbolInfo>>); pub struct SymbolInfoLookup<'a>(Option<&'a [SymbolInfo]>);
impl<'a> SymbolInfoLookup<'a> { impl<'a> SymbolInfoLookup<'a> {
pub const fn new() -> Self { pub const fn new() -> Self {
Self(None) Self(None)
@@ -233,7 +230,7 @@ impl<'a> SymbolInfoLookup<'a> {
* *
* @param override the symbol info set to use * @param override the symbol info set to use
*/ */
pub fn overrideSymbolSet(&mut self, override_symbols: &'a Vec<SymbolInfo>) { pub fn overrideSymbolSet(&mut self, override_symbols: &'a [SymbolInfo]) {
self.0 = Some(override_symbols); self.0 = Some(override_symbols);
} }
@@ -281,7 +278,7 @@ impl<'a> SymbolInfoLookup<'a> {
fail: bool, fail: bool,
// alternate_symbols_chart: Option<&'a Vec<SymbolInfo>>, // alternate_symbols_chart: Option<&'a Vec<SymbolInfo>>,
) -> Result<Option<&'a SymbolInfo>> { ) -> Result<Option<&'a SymbolInfo>> {
let symbol_search_chart: &Vec<SymbolInfo> = if self.0.is_none() { let symbol_search_chart: &[SymbolInfo] = if self.0.is_none() {
&PROD_SYMBOLS &PROD_SYMBOLS
} else { } else {
self.0.as_ref().unwrap() self.0.as_ref().unwrap()

View File

@@ -36,6 +36,7 @@ impl TextEncoder {
pub fn new() -> Self { pub fn new() -> Self {
Self(C40Encoder::new()) Self(C40Encoder::new())
} }
fn encodeChar(c: char, sb: &mut String) -> u32 { fn encodeChar(c: char, sb: &mut String) -> u32 {
if c == ' ' { if c == ' ' {
sb.push('\u{3}'); sb.push('\u{3}');

View File

@@ -108,10 +108,6 @@ impl Reader for MaxiCodeReader {
Ok(result) Ok(result)
} }
fn reset(&mut self) {
// do nothing
}
} }
impl MaxiCodeReader { impl MaxiCodeReader {
pub const MATRIX_WIDTH: u32 = 30; pub const MATRIX_WIDTH: u32 = 30;

View File

@@ -68,17 +68,19 @@ impl From<PointU> for Point {
} }
/** An alias for `Point::new`. */ /** An alias for `Point::new`. */
#[inline]
pub const fn point_f(x: f32, y: f32) -> Point { pub const fn point_f(x: f32, y: f32) -> Point {
Point::new(x, y) Point::new(x, y)
} }
#[inline]
pub const fn point<T>(x: T, y: T) -> PointT<T> pub const fn point<T>(x: T, y: T) -> PointT<T>
where where
T: Copy, T: Copy,
{ {
PointT::new(x, y) PointT::new(x, y)
} }
#[inline]
pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point { pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {
Point::new(x.into() as f32, y.into() as f32) Point::new(x.into() as f32, y.into() as f32)
} }