Skip to content

Commit

Permalink
Specialize Iterator::{size_hint,count}
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed May 2, 2015
1 parent 5e73cfd commit 7ab69e1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/number_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const U64_BYTES: usize = 8;

macro_rules! number_stream(
($name:ident, $number_type:ty, $bytes_in_type:expr) => (
#[allow(raw_pointer_derive)]
#[derive(Debug,Copy,Clone)]
struct $name<'a> {
start: *const $number_type,
end: *const $number_type,
Expand Down Expand Up @@ -42,6 +44,16 @@ impl<'a> Iterator for $name<'a> {
self.start = unsafe { self.start.offset(1) };
Some(v)
}

fn size_hint(&self) -> (usize, Option<usize>) {
let cnt = self.count();
(cnt, Some(cnt))
}

fn count(self) -> usize() {
let total_bytes = self.end as usize - self.start as usize;
total_bytes / $bytes_in_type
}
}
));

Expand Down

0 comments on commit 7ab69e1

Please sign in to comment.