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

@@ -56,11 +56,7 @@ fn test_short_shift_jis1() {
#[test]
fn test_short_iso885911() {
// båd
do_test(
&[0x62, 0xe5, 0x64],
encoding::all::ISO_8859_1,
"ISO8859_1",
);
do_test(&[0x62, 0xe5, 0x64], encoding::all::ISO_8859_1, "ISO8859_1");
}
#[test]

View File

@@ -28,23 +28,22 @@ use unicode_segmentation::UnicodeSegmentation;
use super::CharacterSetECI;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
lazy_static! {
static ref ENCODERS : Vec<EncodingRef> = {
let mut enc_vec = Vec::new();
for name in NAMES {
if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) {
// try {
enc_vec.push(CharacterSetECI::getCharset(&enc));
// } catch (UnsupportedCharsetException e) {
// continue
// }
}
static ENCODERS: Lazy<Vec<EncodingRef>> = Lazy::new(|| {
let mut enc_vec = Vec::new();
for name in NAMES {
if let Some(enc) = CharacterSetECI::getCharacterSetECIByName(name) {
// try {
enc_vec.push(CharacterSetECI::getCharset(&enc));
// } catch (UnsupportedCharsetException e) {
// continue
// }
}
enc_vec
};
}
}
enc_vec
});
const NAMES: [&str; 20] = [
"IBM437",
"ISO-8859-2",

View File

@@ -22,18 +22,14 @@ pub(crate) mod ReedSolomonTestCase;
//package com.google.zxing.common.reedsolomon;
pub type GenericGFRef = &'static GenericGF;
use once_cell::sync::Lazy;
use lazy_static::lazy_static;
lazy_static! {
static ref AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
static ref AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1
static ref AZTEC_DATA_6: GenericGF = GenericGF::new(0x43, 64, 1); // x^6 + x + 1
static ref AZTEC_PARAM: GenericGF = GenericGF::new(0x13, 16, 1); // x^4 + x + 1
static ref QR_CODE_FIELD_256: GenericGF = GenericGF::new(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1
static ref DATA_MATRIX_FIELD_256: GenericGF = GenericGF::new(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1
// static ref PDF_417_FIELD: GenericGF = GenericGF::new(3,crate::pdf417::pdf_417_common::NUMBER_OF_CODEWORDS as usize,1);
}
static AZTEC_DATA_12: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x1069, 4096, 1)); // x^12 + x^6 + x^5 + x^3 + 1
static AZTEC_DATA_10: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x409, 1024, 1)); // x^10 + x^3 + 1
static AZTEC_DATA_6: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x43, 64, 1)); // x^6 + x + 1
static AZTEC_PARAM: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x13, 16, 1)); // x^4 + x + 1
static QR_CODE_FIELD_256: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x011D, 256, 0)); // x^8 + x^4 + x^3 + x^2 + 1
static DATA_MATRIX_FIELD_256: Lazy<GenericGF> = Lazy::new(|| GenericGF::new(0x012D, 256, 1)); // x^8 + x^5 + x^3 + x^2 + 1
// pub const AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
// pub const AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1

View File

@@ -24,7 +24,7 @@ use encoding::{Encoding, EncodingRef};
use crate::{DecodeHintType, DecodeHintValue, DecodingHintDictionary};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
/**
* Common string-related functions.
@@ -55,10 +55,9 @@ pub struct StringUtils {
const ASSUME_SHIFT_JIS: bool = false;
// static SHIFT_JIS: &'static str = "SJIS";
// static GB2312: &'static str = "GB2312";
lazy_static! {
pub static ref SHIFT_JIS_CHARSET: EncodingRef =
encoding::label::encoding_from_whatwg_label("SJIS").unwrap();
}
pub static SHIFT_JIS_CHARSET: Lazy<EncodingRef> =
Lazy::new(|| encoding::label::encoding_from_whatwg_label("SJIS").unwrap());
// private static final boolean ASSUME_SHIFT_JIS =
// SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||