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

@@ -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",