improve 16 iter

master
Avril 4 years ago
parent 13265c8529
commit b701c246f5
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,7 +1,7 @@
[package]
name = "khash"
description = "Kana hashes"
version = "2.0.1"
version = "2.0.2"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"
license = "GPL-3.0-or-later"

@ -29,7 +29,7 @@ $(DEBUG)/lib$(PROJECT).so:
.PHONY: khash-nonative
khash-nonative:
$(MAKE) RUSTFLAGS="" $(BUILD)/libkhash.so
$(MAKE) $(BUILD)/libkhash.so
.PHONY: test
test: RUSTFLAGS+= -C target-cpu=native -C opt-level=3

@ -15,17 +15,6 @@ where I: Iterator,
type Item = u16;
fn next(&mut self) -> Option<Self::Item>
{
/*let mut c = 0u16;
unsafe {
if let Some(a) = self.iter.next() {
crate::reinterpret::bytes_mut(&mut c)[0] = *a.borrow();
} else {
return None;
}
if let Some(b) = self.iter.next() {
crate::reinterpret::bytes_mut(&mut c)[1] = *b.borrow();
}
}*/
let mut ar = [0u8; std::mem::size_of::<u16>()];
if let Some(a) = self.iter.next()
{
@ -39,8 +28,20 @@ where I: Iterator,
}
Some(u16::from_le_bytes(ar))
}
fn size_hint(&self) -> (usize, Option<usize>) {
let (l, h) = self.iter.size_hint();
(l/2, h.map(|x| x/2))
}
}
impl<I> std::iter::FusedIterator for Bit16Iter<I>
where I: Iterator + std::iter::FusedIterator,
<I as Iterator>::Item: Borrow<u8>{}
impl<I> ExactSizeIterator for Bit16Iter<I>
where I: Iterator + ExactSizeIterator,
<I as Iterator>::Item: Borrow<u8>{}
pub trait Bit16IterExt: Iterator + Sized
where <Self as Iterator>::Item: Borrow<u8>
{

Loading…
Cancel
Save