mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
fix performance issue in PatternView:
Previously converting from a `PatternView` to an array reference required an intermediary step, and the creation of a new array on the stack. The new implementation can pass a reference to the underyling data directly, without that intermediary allocation.
This commit is contained in:
@@ -348,6 +348,16 @@ impl<'a, const LEN: usize> From<&PatternView<'a>> for [PatternType; LEN] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&PatternView<'a>> for &'a [PatternType] {
|
||||||
|
fn from(value: &PatternView<'a>) -> Self {
|
||||||
|
if value.data.0.len() == value.count {
|
||||||
|
&value.data.0
|
||||||
|
} else {
|
||||||
|
&value.data.0[value.current + value.start..=value.current + value.start + value.count]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The BarAndSpace struct is a simple 2 element data structure to hold information about bar(s) and space(s).
|
* @brief The BarAndSpace struct is a simple 2 element data structure to hold information about bar(s) and space(s).
|
||||||
*
|
*
|
||||||
@@ -476,8 +486,8 @@ pub fn IsPattern<const E2E: bool, const LEN: usize, const SUM: usize, const SPAR
|
|||||||
|
|
||||||
if E2E {
|
if E2E {
|
||||||
//using float_t = double;
|
//using float_t = double;
|
||||||
let v_src: [PatternType; LEN] = view.into();
|
// let v_src: [PatternType; LEN] = view.into();
|
||||||
let widths = BarAndSpaceSum::<LEN, PatternType, f64>(&v_src);
|
let widths = BarAndSpaceSum::<LEN, PatternType, f64>(view.into());
|
||||||
let sums = pattern.sums();
|
let sums = pattern.sums();
|
||||||
let modSize: BarAndSpace<f64> = BarAndSpace {
|
let modSize: BarAndSpace<f64> = BarAndSpace {
|
||||||
bar: widths[0] / sums[0] as f64,
|
bar: widths[0] / sums[0] as f64,
|
||||||
|
|||||||
Reference in New Issue
Block a user