Skip to content

Commit

Permalink
perf: remove many instances of unecessary Lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed Dec 22, 2024
1 parent 7b53145 commit dc7b8af
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/binary_bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ impl<B: Binarizer> fmt::Display for BinaryBitmap<B> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.matrix.borrow())
}
}
}
18 changes: 9 additions & 9 deletions src/datamatrix/decoder/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,31 @@ impl Version {
}
}

pub fn getVersionNumber(&self) -> u32 {
pub const fn getVersionNumber(&self) -> u32 {
self.versionNumber
}

pub fn getSymbolSizeRows(&self) -> u32 {
pub const fn getSymbolSizeRows(&self) -> u32 {
self.symbolSizeRows
}

pub fn getSymbolSizeColumns(&self) -> u32 {
pub const fn getSymbolSizeColumns(&self) -> u32 {
self.symbolSizeColumns
}

pub fn getDataRegionSizeRows(&self) -> u32 {
pub const fn getDataRegionSizeRows(&self) -> u32 {
self.dataRegionSizeRows
}

pub fn getDataRegionSizeColumns(&self) -> u32 {
pub const fn getDataRegionSizeColumns(&self) -> u32 {
self.dataRegionSizeColumns
}

pub fn getTotalCodewords(&self) -> u32 {
pub const fn getTotalCodewords(&self) -> u32 {
self.totalCodewords
}

pub fn getECBlocks(&self) -> &ECBlocks {
pub const fn getECBlocks(&self) -> &ECBlocks {
&self.ecBlocks
}

Expand Down Expand Up @@ -212,11 +212,11 @@ impl ECBlocks {
}
}

pub fn getECCodewords(&self) -> u32 {
pub const fn getECCodewords(&self) -> u32 {
self.ecCodewords
}

pub fn getECBlocks(&self) -> &[ECB] {
pub const fn getECBlocks(&self) -> &[ECB] {
&self.ecBlocks
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/datamatrix/encoder/symbol_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,20 @@ impl SymbolInfo {
}
}
pub const fn new_symbol_info_144() -> Self {
let mut new_symbol = Self::with_details(false, 1558, 620, 22, 22, 36, -1, 62);
new_symbol.isSymbolInfo144 = true;
new_symbol
Self {
rectangular: false,
dataCapacity: 1558,
errorCodewords: 620,
matrixWidth:22,
matrixHeight:22,
dataRegions:36,
rsBlockData:-1,
rsBlockError:62,
isSymbolInfo144: true,
}
// let mut new_symbol = Self::with_details(false, 1558, 620, 22, 22, 36, -1, 62);
// new_symbol.isSymbolInfo144 = true;
// new_symbol
}

fn getHorizontalDataRegions(&self) -> Result<u32> {
Expand Down
221 changes: 109 additions & 112 deletions src/oned/code_128_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,119 +431,116 @@ impl Code128Reader {
}
}

use once_cell::sync::Lazy;

pub static CODE_PATTERNS: Lazy<[Box<[u32]>; 107]> = Lazy::new(|| {
pub const CODE_PATTERNS: [&[u32]; 107] =
[
Box::new([2, 1, 2, 2, 2, 2]), // 0
Box::new([2, 2, 2, 1, 2, 2]),
Box::new([2, 2, 2, 2, 2, 1]),
Box::new([1, 2, 1, 2, 2, 3]),
Box::new([1, 2, 1, 3, 2, 2]),
Box::new([1, 3, 1, 2, 2, 2]), // 5
Box::new([1, 2, 2, 2, 1, 3]),
Box::new([1, 2, 2, 3, 1, 2]),
Box::new([1, 3, 2, 2, 1, 2]),
Box::new([2, 2, 1, 2, 1, 3]),
Box::new([2, 2, 1, 3, 1, 2]), // 10
Box::new([2, 3, 1, 2, 1, 2]),
Box::new([1, 1, 2, 2, 3, 2]),
Box::new([1, 2, 2, 1, 3, 2]),
Box::new([1, 2, 2, 2, 3, 1]),
Box::new([1, 1, 3, 2, 2, 2]), // 15
Box::new([1, 2, 3, 1, 2, 2]),
Box::new([1, 2, 3, 2, 2, 1]),
Box::new([2, 2, 3, 2, 1, 1]),
Box::new([2, 2, 1, 1, 3, 2]),
Box::new([2, 2, 1, 2, 3, 1]), // 20
Box::new([2, 1, 3, 2, 1, 2]),
Box::new([2, 2, 3, 1, 1, 2]),
Box::new([3, 1, 2, 1, 3, 1]),
Box::new([3, 1, 1, 2, 2, 2]),
Box::new([3, 2, 1, 1, 2, 2]), // 25
Box::new([3, 2, 1, 2, 2, 1]),
Box::new([3, 1, 2, 2, 1, 2]),
Box::new([3, 2, 2, 1, 1, 2]),
Box::new([3, 2, 2, 2, 1, 1]),
Box::new([2, 1, 2, 1, 2, 3]), // 30
Box::new([2, 1, 2, 3, 2, 1]),
Box::new([2, 3, 2, 1, 2, 1]),
Box::new([1, 1, 1, 3, 2, 3]),
Box::new([1, 3, 1, 1, 2, 3]),
Box::new([1, 3, 1, 3, 2, 1]), // 35
Box::new([1, 1, 2, 3, 1, 3]),
Box::new([1, 3, 2, 1, 1, 3]),
Box::new([1, 3, 2, 3, 1, 1]),
Box::new([2, 1, 1, 3, 1, 3]),
Box::new([2, 3, 1, 1, 1, 3]), // 40
Box::new([2, 3, 1, 3, 1, 1]),
Box::new([1, 1, 2, 1, 3, 3]),
Box::new([1, 1, 2, 3, 3, 1]),
Box::new([1, 3, 2, 1, 3, 1]),
Box::new([1, 1, 3, 1, 2, 3]), // 45
Box::new([1, 1, 3, 3, 2, 1]),
Box::new([1, 3, 3, 1, 2, 1]),
Box::new([3, 1, 3, 1, 2, 1]),
Box::new([2, 1, 1, 3, 3, 1]),
Box::new([2, 3, 1, 1, 3, 1]), // 50
Box::new([2, 1, 3, 1, 1, 3]),
Box::new([2, 1, 3, 3, 1, 1]),
Box::new([2, 1, 3, 1, 3, 1]),
Box::new([3, 1, 1, 1, 2, 3]),
Box::new([3, 1, 1, 3, 2, 1]), // 55
Box::new([3, 3, 1, 1, 2, 1]),
Box::new([3, 1, 2, 1, 1, 3]),
Box::new([3, 1, 2, 3, 1, 1]),
Box::new([3, 3, 2, 1, 1, 1]),
Box::new([3, 1, 4, 1, 1, 1]), // 60
Box::new([2, 2, 1, 4, 1, 1]),
Box::new([4, 3, 1, 1, 1, 1]),
Box::new([1, 1, 1, 2, 2, 4]),
Box::new([1, 1, 1, 4, 2, 2]),
Box::new([1, 2, 1, 1, 2, 4]), // 65
Box::new([1, 2, 1, 4, 2, 1]),
Box::new([1, 4, 1, 1, 2, 2]),
Box::new([1, 4, 1, 2, 2, 1]),
Box::new([1, 1, 2, 2, 1, 4]),
Box::new([1, 1, 2, 4, 1, 2]), // 70
Box::new([1, 2, 2, 1, 1, 4]),
Box::new([1, 2, 2, 4, 1, 1]),
Box::new([1, 4, 2, 1, 1, 2]),
Box::new([1, 4, 2, 2, 1, 1]),
Box::new([2, 4, 1, 2, 1, 1]), // 75
Box::new([2, 2, 1, 1, 1, 4]),
Box::new([4, 1, 3, 1, 1, 1]),
Box::new([2, 4, 1, 1, 1, 2]),
Box::new([1, 3, 4, 1, 1, 1]),
Box::new([1, 1, 1, 2, 4, 2]), // 80
Box::new([1, 2, 1, 1, 4, 2]),
Box::new([1, 2, 1, 2, 4, 1]),
Box::new([1, 1, 4, 2, 1, 2]),
Box::new([1, 2, 4, 1, 1, 2]),
Box::new([1, 2, 4, 2, 1, 1]), // 85
Box::new([4, 1, 1, 2, 1, 2]),
Box::new([4, 2, 1, 1, 1, 2]),
Box::new([4, 2, 1, 2, 1, 1]),
Box::new([2, 1, 2, 1, 4, 1]),
Box::new([2, 1, 4, 1, 2, 1]), // 90
Box::new([4, 1, 2, 1, 2, 1]),
Box::new([1, 1, 1, 1, 4, 3]),
Box::new([1, 1, 1, 3, 4, 1]),
Box::new([1, 3, 1, 1, 4, 1]),
Box::new([1, 1, 4, 1, 1, 3]), // 95
Box::new([1, 1, 4, 3, 1, 1]),
Box::new([4, 1, 1, 1, 1, 3]),
Box::new([4, 1, 1, 3, 1, 1]),
Box::new([1, 1, 3, 1, 4, 1]),
Box::new([1, 1, 4, 1, 3, 1]), // 100
Box::new([3, 1, 1, 1, 4, 1]),
Box::new([4, 1, 1, 1, 3, 1]),
Box::new([2, 1, 1, 4, 1, 2]),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4, 1, 1, 3], // 95
&[1, 1, 4, 3, 1, 1],
&[4, 1, 1, 1, 1, 3],
&[4, 1, 1, 3, 1, 1],
&[1, 1, 3, 1, 4, 1],
&[1, 1, 4, 1, 3, 1], // 100
&[3, 1, 1, 1, 4, 1],
&[4, 1, 1, 1, 3, 1],
&[2, 1, 1, 4, 1, 2],
&[2, 1, 1, 2, 1, 4],
&[2, 1, 1, 2, 3, 2], // 105
&[2, 3, 3, 1, 1, 1, 2],
];

const MAX_AVG_VARIANCE: f32 = 0.25;
const MAX_INDIVIDUAL_VARIANCE: f32 = 0.7;
Expand Down
24 changes: 11 additions & 13 deletions src/pdf417/encoder/pdf_417_error_correction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* PDF417 error correction code following the algorithm described in ISO/IEC 15438:2001(E) in
* chapter 4.10.
*/
use once_cell::sync::Lazy;

use crate::common::Result;
use crate::Exceptions;
Expand All @@ -31,25 +30,25 @@ use crate::Exceptions;
* Tables of coefficients for calculating error correction words
* (see annex F, ISO/IEC 15438:2001(E))
*/
static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
const EC_COEFFICIENTS: [&[u32]; 9] =
[
vec![27, 917],
vec![522, 568, 723, 809],
vec![237, 308, 436, 284, 646, 653, 428, 379],
vec![
&[27, 917],
&[522, 568, 723, 809],
&[237, 308, 436, 284, 646, 653, 428, 379],
&[
274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 42, 176, 65,
],
vec![
&[
361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 284, 193, 517, 273,
494, 263, 147, 593, 800, 571, 320, 803, 133, 231, 390, 685, 330, 63, 410,
],
vec![
&[
539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, 877, 381, 612, 723, 476,
462, 172, 430, 609, 858, 822, 543, 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31,
460, 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, 733, 717, 83, 404, 97,
280, 771, 840, 629, 4, 381, 843, 623, 264, 543,
],
vec![
&[
521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, 925, 749, 415, 822, 93,
217, 208, 928, 244, 583, 620, 246, 148, 447, 631, 292, 908, 490, 704, 516, 258, 457,
907, 594, 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, 219, 129, 186,
Expand All @@ -59,7 +58,7 @@ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
454, 354, 130, 814, 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, 315, 550,
86, 801, 4, 108, 539,
],
vec![
&[
524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, 786, 138, 720, 858, 194,
311, 913, 275, 190, 375, 850, 438, 733, 194, 280, 201, 280, 828, 757, 710, 814, 919,
89, 68, 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, 418, 592, 668, 353,
Expand All @@ -76,7 +75,7 @@ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, 251, 688, 95, 497, 555, 642, 543,
307, 159, 924, 558, 648, 55, 497, 10,
],
vec![
&[
352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, 380, 350, 492, 197, 265,
920, 155, 914, 299, 229, 643, 294, 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520,
435, 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, 781, 408, 390, 644,
Expand Down Expand Up @@ -108,8 +107,7 @@ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
768, 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121,
303, 263,
],
]
});
];

/**
* Determines the number of error correction codewords for a specified error correction
Expand Down
3 changes: 1 addition & 2 deletions src/qrcode/encoder/EncoderTestCase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ use crate::{
},
EncodeHintType, EncodeHintValue,
};
use once_cell::sync::Lazy;

use super::QRCode;

static SHIFT_JIS_CHARSET: Lazy<CharacterSet> = Lazy::new(|| CharacterSet::Shift_JIS);
const SHIFT_JIS_CHARSET: CharacterSet = CharacterSet::Shift_JIS;

/**
* @author satorux@google.com (Satoru Takabayashi) - creator
Expand Down

0 comments on commit dc7b8af

Please sign in to comment.