diff --git a/src/common/bit_array.rs b/src/common/bit_array.rs index bc05ac1..c3ba94b 100644 --- a/src/common/bit_array.rs +++ b/src/common/bit_array.rs @@ -22,7 +22,6 @@ use std::{cmp, fmt}; use crate::Exceptions; -static EMPTY_BITS: [u32; 0] = [0; 0]; static LOAD_FACTOR: f32 = 0.75f32; /** @@ -39,7 +38,7 @@ pub struct BitArray { impl BitArray { pub fn new() -> Self { Self { - bits: EMPTY_BITS.to_vec(), + bits: Vec::new(), size: 0, } } @@ -327,7 +326,7 @@ impl BitArray { * @return underlying array of ints. The first element holds the first 32 bits, and the least * significant bit is bit 0. */ - pub fn getBitArray(&self) -> &Vec { + pub fn getBitArray(&self) -> &[u32] { &self.bits } diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index 221641e..68b3e27 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -215,6 +215,7 @@ impl BitMatrix { Ok(((self.bits[offset] >> (x & 0x1f)) & 1) != 0) } + /// Confusingly returns true if the requested element is out of bounds pub fn check_in_bounds(&self, x: u32, y: u32) -> bool { (y as usize * self.row_size + (x as usize / 32)) > self.bits.len() } diff --git a/src/common/global_histogram_binarizer.rs b/src/common/global_histogram_binarizer.rs index 13a47d1..2212eee 100644 --- a/src/common/global_histogram_binarizer.rs +++ b/src/common/global_histogram_binarizer.rs @@ -40,7 +40,7 @@ use super::{BitArray, BitMatrix}; * @author Sean Owen */ pub struct GlobalHistogramBinarizer { - _luminances: Vec, + //_luminances: Vec, width: usize, height: usize, source: Box, @@ -134,7 +134,7 @@ impl GlobalHistogramBinarizer { pub fn new(source: Box) -> Self { Self { - _luminances: vec![0; source.getWidth()], + //_luminances: vec![0; source.getWidth()], width: source.getWidth(), height: source.getHeight(), black_matrix: OnceCell::new(), diff --git a/src/common/reedsolomon/generic_gf_poly.rs b/src/common/reedsolomon/generic_gf_poly.rs index ab64f54..721f0d0 100644 --- a/src/common/reedsolomon/generic_gf_poly.rs +++ b/src/common/reedsolomon/generic_gf_poly.rs @@ -47,7 +47,7 @@ impl GenericGFPoly { * or if leading coefficient is 0 and this is not a * constant polynomial (that is, it is not the monomial "0") */ - pub fn new(field: GenericGFRef, coefficients: &Vec) -> Result { + pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result { if coefficients.is_empty() { return Err(Exceptions::IllegalArgumentException(Some( "coefficients.len()".to_owned(), diff --git a/src/common/reedsolomon/reedsolomon_decoder.rs b/src/common/reedsolomon/reedsolomon_decoder.rs index e5178bd..c43655b 100644 --- a/src/common/reedsolomon/reedsolomon_decoder.rs +++ b/src/common/reedsolomon/reedsolomon_decoder.rs @@ -76,9 +76,8 @@ impl ReedSolomonDecoder { if noError { return Ok(0); } - let syndrome = match GenericGFPoly::new(self.field, &syndromeCoefficients) { - Ok(res) => res, - Err(_fail) => return Err(Exceptions::ReedSolomonException(None)), + let Ok(syndrome) = GenericGFPoly::new(self.field, &syndromeCoefficients) else { + return Err(Exceptions::ReedSolomonException(None)); }; let sigmaOmega = self.runEuclideanAlgorithm( &GenericGF::buildMonomial(self.field, twoS as usize, 1), diff --git a/src/common/reedsolomon/reedsolomon_encoder.rs b/src/common/reedsolomon/reedsolomon_encoder.rs index 7fa47a1..7ded62e 100644 --- a/src/common/reedsolomon/reedsolomon_encoder.rs +++ b/src/common/reedsolomon/reedsolomon_encoder.rs @@ -38,7 +38,7 @@ impl ReedSolomonEncoder { pub fn new(field: GenericGFRef) -> Self { let n = field; Self { - cachedGenerators: vec![GenericGFPoly::new(n, &vec![1]).unwrap()], + cachedGenerators: vec![GenericGFPoly::new(n, &[1]).unwrap()], field: n, } } diff --git a/src/common/string_utils.rs b/src/common/string_utils.rs index 29893b1..46843e2 100644 --- a/src/common/string_utils.rs +++ b/src/common/string_utils.rs @@ -71,20 +71,21 @@ impl StringUtils { * "SJIS", "UTF8", "ISO8859_1", or the platform default encoding if none * of these can possibly be correct */ - pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> String { + pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> &'static str { let c = StringUtils::guessCharset(bytes, hints); if c.name() == encoding::label::encoding_from_whatwg_label("SJIS") .unwrap() .name() { - return "SJIS".to_owned(); + "SJIS" } else if c.name() == encoding::all::UTF_8.name() { - return "UTF8".to_owned(); + "UTF8" } else if c.name() == encoding::all::ISO_8859_1.name() { - return "ISO8859_1".to_owned(); + "ISO8859_1" + }else { + c.name() } - return c.name().to_owned(); } /**