0.17.2 improve performance of MatConstIterator, remove excessive #[inline] in Mat
MODIFY
Cargo.toml
Cargo.toml
@@ -6,7 +6,7 @@ repository = "https://github.com/twistedfall/opencv-rust"
readme = "README.md"
keywords = [ "opencv", "vision" ]
license = "MIT"
-version = "0.17.1"
+version = "0.17.2"
edition = "2018"
authors = ["Mathieu Poumeyrol <kali@zoy.org>", "Pro <twisted.fall@gmail.com>"]
build = "build.rs"

MODIFY
src/manual/core/mat.rs
src/manual/core/mat.rs
use std::{
- ffi::c_void,
fmt,
ops::Deref,
slice,
@@ -102,10 +101,7 @@ fn convert_ptr_mut<T>(r: &mut u8) -> &mut T {
unsafe { &mut *(r as *mut _ as *mut T) }
}
-impl Mat {
- #[inline(always)]
- fn match_format<T: DataType>(&self) -> Result<()> {
- let mat_type = self.typ()?;
+fn match_format<T: DataType>(mat_type: i32) -> Result<()> {
let out_type = T::typ();
if mat_type == out_type {
Ok(())
@@ -118,7 +114,12 @@ impl Mat {
}
}
+impl Mat {
#[inline(always)]
+ fn match_format<T: DataType>(&self) -> Result<()> {
+ match_format::<T>(self.typ()?)
+ }
+
fn match_dims(&self, dims: usize) -> Result<()> {
let mat_dims = self.dims()? as usize;
if mat_dims == dims {
@@ -128,7 +129,6 @@ impl Mat {
}
}
- #[inline(always)]
fn match_indices(&self, idx: &[i32]) -> Result<()> {
let size = self.mat_size()?;
self.match_dims(idx.len())?;
@@ -142,7 +142,6 @@ impl Mat {
}
}
- #[inline(always)]
fn match_total(&self, idx: i32) -> Result<()> {
let size = self.total()?;
if 0 <= idx && (idx as usize) < size {
@@ -519,15 +518,18 @@ impl fmt::Debug for MatStep {
}
impl MatConstIterator {
+ #[inline(always)]
+ fn match_format<T: DataType>(&self) -> Result<()> {
+ match_format::<T>(self.typ())
+ }
+
#[inline]
- fn m(&self) -> Mat {
+ pub fn typ(&self) -> i32 {
let me = self.as_raw_MatConstIterator();
- Mat {
- ptr: cpp!(unsafe [me as "const MatConstIterator*"] -> *mut c_void as "const void*" {
- return reinterpret_cast<const void*>(new cv::Mat(*me->m));
+ cpp!(unsafe [me as "const MatConstIterator*"] -> i32 as "int" {
+ return me->m->type();
})
}
- }
#[inline]
pub fn has_elements(&self) -> bool {
@@ -538,7 +540,7 @@ impl MatConstIterator {
}
pub fn get<T: DataType>(&self) -> Result<&T> {
- self.m().match_format::<T>()?;
+ self.match_format::<T>()?;
if self.has_elements() {
unsafe { self.get_unchecked() }
} else {

MODIFY
tests/mat.rs
tests/mat.rs
@@ -391,6 +391,7 @@ fn mat_from_data() -> Result<()> {
fn mat_iterator() -> Result<()> {
let mat = Mat::from_slice(&[1, 2, 3, 4])?;
let mut iter = MatConstIterator::over(&mat)?;
+ assert_eq!(iter.typ(), mat.typ()?);
assert_eq!(1, *iter.get::<i32>()?);
assert_eq!(Point::new(0, 0), iter.pos()?);
assert!(iter.has_elements());

0.17.2 improve performance of MatConstIterator, remove excessive #[inline] in Mat