change to using once_cell for lazy init

This commit is contained in:
Henry Schimke
2023-01-05 10:53:55 -06:00
parent d2a4b21808
commit 20764559ae
37 changed files with 556 additions and 608 deletions

View File

@@ -27,16 +27,14 @@
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::{common::BitArray, Exceptions};
lazy_static! {
static ref ONE: Regex = Regex::new("1").unwrap();
static ref ZERO: Regex = Regex::new("0").unwrap();
static ref SPACE: Regex = Regex::new(" ").unwrap();
}
static ONE: Lazy<Regex> = Lazy::new(|| Regex::new("1").unwrap());
static ZERO: Lazy<Regex> = Lazy::new(|| Regex::new("0").unwrap());
static SPACE: Lazy<Regex> = Lazy::new(|| Regex::new(" ").unwrap());
/*
* Constructs a BitArray from a String like the one returned from BitArray.toString()

View File

@@ -31,115 +31,111 @@ use std::collections::HashMap;
use crate::Exceptions;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
lazy_static! {
static TWO_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new();
hm.insert("00".to_owned(), DataLength::fixed(18));
hm.insert("01".to_owned(), DataLength::fixed(14));
hm.insert("02".to_owned(), DataLength::fixed(14));
hm.insert("10".to_owned(), DataLength::variable(20));
hm.insert("11".to_owned(), DataLength::fixed(6));
hm.insert("12".to_owned(), DataLength::fixed(6));
hm.insert("13".to_owned(), DataLength::fixed(6));
hm.insert("15".to_owned(), DataLength::fixed(6));
hm.insert("17".to_owned(), DataLength::fixed(6));
hm.insert("20".to_owned(), DataLength::fixed(2));
hm.insert("21".to_owned(), DataLength::variable(20));
hm.insert("22".to_owned(), DataLength::variable(29));
hm.insert("30".to_owned(), DataLength::variable(8));
hm.insert("37".to_owned(), DataLength::variable(8));
//internal company codes
for i in 90..=99 {
// for (int i = 90; i <= 99; i++) {
hm.insert(i.to_string(), DataLength::variable(30));
}
hm
});
static ref TWO_DIGIT_DATA_LENGTH : HashMap<String,DataLength> = {
let mut hm = HashMap::new();
hm.insert("00".to_owned(), DataLength::fixed(18));
hm.insert("01".to_owned(), DataLength::fixed(14));
hm.insert("02".to_owned(), DataLength::fixed(14));
hm.insert("10".to_owned(), DataLength::variable(20));
hm.insert("11".to_owned(), DataLength::fixed(6));
hm.insert("12".to_owned(), DataLength::fixed(6));
hm.insert("13".to_owned(), DataLength::fixed(6));
hm.insert("15".to_owned(), DataLength::fixed(6));
hm.insert("17".to_owned(), DataLength::fixed(6));
hm.insert("20".to_owned(), DataLength::fixed(2));
hm.insert("21".to_owned(), DataLength::variable(20));
hm.insert("22".to_owned(), DataLength::variable(29));
hm.insert("30".to_owned(), DataLength::variable(8));
hm.insert("37".to_owned(), DataLength::variable(8));
//internal company codes
for i in 90..=99 {
// for (int i = 90; i <= 99; i++) {
hm.insert(i.to_string(), DataLength::variable(30));
}
hm
};
static THREE_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new();
hm.insert("240".to_owned(), DataLength::variable(30));
hm.insert("241".to_owned(), DataLength::variable(30));
hm.insert("242".to_owned(), DataLength::variable(6));
hm.insert("250".to_owned(), DataLength::variable(30));
hm.insert("251".to_owned(), DataLength::variable(30));
hm.insert("253".to_owned(), DataLength::variable(17));
hm.insert("254".to_owned(), DataLength::variable(20));
hm.insert("400".to_owned(), DataLength::variable(30));
hm.insert("401".to_owned(), DataLength::variable(30));
hm.insert("402".to_owned(), DataLength::fixed(17));
hm.insert("403".to_owned(), DataLength::variable(30));
hm.insert("410".to_owned(), DataLength::fixed(13));
hm.insert("411".to_owned(), DataLength::fixed(13));
hm.insert("412".to_owned(), DataLength::fixed(13));
hm.insert("413".to_owned(), DataLength::fixed(13));
hm.insert("414".to_owned(), DataLength::fixed(13));
hm.insert("420".to_owned(), DataLength::variable(20));
hm.insert("421".to_owned(), DataLength::variable(15));
hm.insert("422".to_owned(), DataLength::fixed(3));
hm.insert("423".to_owned(), DataLength::variable(15));
hm.insert("424".to_owned(), DataLength::fixed(3));
hm.insert("425".to_owned(), DataLength::fixed(3));
hm.insert("426".to_owned(), DataLength::fixed(3));
static ref THREE_DIGIT_DATA_LENGTH : HashMap<String,DataLength>=
{
let mut hm = HashMap::new();
hm.insert("240".to_owned(), DataLength::variable(30));
hm.insert("241".to_owned(), DataLength::variable(30));
hm.insert("242".to_owned(), DataLength::variable(6));
hm.insert("250".to_owned(), DataLength::variable(30));
hm.insert("251".to_owned(), DataLength::variable(30));
hm.insert("253".to_owned(), DataLength::variable(17));
hm.insert("254".to_owned(), DataLength::variable(20));
hm.insert("400".to_owned(), DataLength::variable(30));
hm.insert("401".to_owned(), DataLength::variable(30));
hm.insert("402".to_owned(), DataLength::fixed(17));
hm.insert("403".to_owned(), DataLength::variable(30));
hm.insert("410".to_owned(), DataLength::fixed(13));
hm.insert("411".to_owned(), DataLength::fixed(13));
hm.insert("412".to_owned(), DataLength::fixed(13));
hm.insert("413".to_owned(), DataLength::fixed(13));
hm.insert("414".to_owned(), DataLength::fixed(13));
hm.insert("420".to_owned(), DataLength::variable(20));
hm.insert("421".to_owned(), DataLength::variable(15));
hm.insert("422".to_owned(), DataLength::fixed(3));
hm.insert("423".to_owned(), DataLength::variable(15));
hm.insert("424".to_owned(), DataLength::fixed(3));
hm.insert("425".to_owned(), DataLength::fixed(3));
hm.insert("426".to_owned(), DataLength::fixed(3));
hm
});
hm
};
static THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new();
for i in 310..=316 {
// for (int i = 310; i <= 316; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 320..=336 {
// for (int i = 320; i <= 336; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 340..=357 {
// for (int i = 340; i <= 357; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 360..=369 {
// for (int i = 360; i <= 369; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
hm.insert("390".to_owned(), DataLength::variable(15));
hm.insert("391".to_owned(), DataLength::variable(18));
hm.insert("392".to_owned(), DataLength::variable(15));
hm.insert("393".to_owned(), DataLength::variable(18));
hm.insert("703".to_owned(), DataLength::variable(30));
static ref THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH:HashMap<String,DataLength> = {
let mut hm = HashMap::new();
for i in 310..=316 {
// for (int i = 310; i <= 316; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 320..=336 {
// for (int i = 320; i <= 336; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 340..=357 {
// for (int i = 340; i <= 357; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
for i in 360..=369 {
// for (int i = 360; i <= 369; i++) {
hm.insert(i.to_string(), DataLength::fixed(6));
}
hm.insert("390".to_owned(), DataLength::variable(15));
hm.insert("391".to_owned(), DataLength::variable(18));
hm.insert("392".to_owned(), DataLength::variable(15));
hm.insert("393".to_owned(), DataLength::variable(18));
hm.insert("703".to_owned(), DataLength::variable(30));
hm
});
hm
};
static FOUR_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(|| {
let mut hm = HashMap::new();
hm.insert("7001".to_owned(), DataLength::fixed(13));
hm.insert("7002".to_owned(), DataLength::variable(30));
hm.insert("7003".to_owned(), DataLength::fixed(10));
hm.insert("8001".to_owned(), DataLength::fixed(14));
hm.insert("8002".to_owned(), DataLength::variable(20));
hm.insert("8003".to_owned(), DataLength::variable(30));
hm.insert("8004".to_owned(), DataLength::variable(30));
hm.insert("8005".to_owned(), DataLength::fixed(6));
hm.insert("8006".to_owned(), DataLength::fixed(18));
hm.insert("8007".to_owned(), DataLength::variable(30));
hm.insert("8008".to_owned(), DataLength::variable(12));
hm.insert("8018".to_owned(), DataLength::fixed(18));
hm.insert("8020".to_owned(), DataLength::variable(25));
hm.insert("8100".to_owned(), DataLength::fixed(6));
hm.insert("8101".to_owned(), DataLength::fixed(10));
hm.insert("8102".to_owned(), DataLength::fixed(2));
hm.insert("8110".to_owned(), DataLength::variable(70));
hm.insert("8200".to_owned(), DataLength::variable(70));
static ref FOUR_DIGIT_DATA_LENGTH : HashMap<String,DataLength>={
let mut hm = HashMap::new();
hm.insert("7001".to_owned(), DataLength::fixed(13));
hm.insert("7002".to_owned(), DataLength::variable(30));
hm.insert("7003".to_owned(), DataLength::fixed(10));
hm.insert("8001".to_owned(), DataLength::fixed(14));
hm.insert("8002".to_owned(), DataLength::variable(20));
hm.insert("8003".to_owned(), DataLength::variable(30));
hm.insert("8004".to_owned(), DataLength::variable(30));
hm.insert("8005".to_owned(), DataLength::fixed(6));
hm.insert("8006".to_owned(), DataLength::fixed(18));
hm.insert("8007".to_owned(), DataLength::variable(30));
hm.insert("8008".to_owned(), DataLength::variable(12));
hm.insert("8018".to_owned(), DataLength::fixed(18));
hm.insert("8020".to_owned(), DataLength::variable(25));
hm.insert("8100".to_owned(), DataLength::fixed(6));
hm.insert("8101".to_owned(), DataLength::fixed(10));
hm.insert("8102".to_owned(), DataLength::fixed(2));
hm.insert("8110".to_owned(), DataLength::variable(70));
hm.insert("8200".to_owned(), DataLength::variable(70));
hm
};
}
hm
});
pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Exceptions> {
if rawInformation.is_empty() {

View File

@@ -40,6 +40,8 @@ use crate::{
RXingResultMetadataType, RXingResultMetadataValue, Reader,
};
use once_cell::sync::Lazy;
use super::{bit_array_builder, decoders::abstract_expanded_decoder, ExpandedPair, ExpandedRow};
const FINDER_PAT_A: u32 = 0;
@@ -49,9 +51,8 @@ const FINDER_PAT_D: u32 = 3;
const FINDER_PAT_E: u32 = 4;
const FINDER_PAT_F: u32 = 5;
use lazy_static::lazy_static;
lazy_static! {
static ref FINDER_PATTERN_SEQUENCES: Vec<Vec<u32>> = vec![
static FINDER_PATTERN_SEQUENCES: Lazy<Vec<Vec<u32>>> = Lazy::new(|| {
vec![
vec![FINDER_PAT_A, FINDER_PAT_A],
vec![FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B],
vec![FINDER_PAT_A, FINDER_PAT_C, FINDER_PAT_B, FINDER_PAT_D],
@@ -60,7 +61,7 @@ lazy_static! {
FINDER_PAT_E,
FINDER_PAT_B,
FINDER_PAT_D,
FINDER_PAT_C
FINDER_PAT_C,
],
vec![
FINDER_PAT_A,
@@ -68,7 +69,7 @@ lazy_static! {
FINDER_PAT_B,
FINDER_PAT_D,
FINDER_PAT_D,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -77,7 +78,7 @@ lazy_static! {
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -87,7 +88,7 @@ lazy_static! {
FINDER_PAT_C,
FINDER_PAT_C,
FINDER_PAT_D,
FINDER_PAT_D
FINDER_PAT_D,
],
vec![
FINDER_PAT_A,
@@ -98,7 +99,7 @@ lazy_static! {
FINDER_PAT_C,
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_E
FINDER_PAT_E,
],
vec![
FINDER_PAT_A,
@@ -110,7 +111,7 @@ lazy_static! {
FINDER_PAT_D,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
vec![
FINDER_PAT_A,
@@ -123,10 +124,10 @@ lazy_static! {
FINDER_PAT_E,
FINDER_PAT_E,
FINDER_PAT_F,
FINDER_PAT_F
FINDER_PAT_F,
],
];
}
]
});
/**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)