Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use self #827

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/bench1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ fn kmerge_tenway(c: &mut Criterion) {
*elt = rng(&mut state);
}

let mut chunks = Vec::new();
let mut chunks = vec![];
let mut rest = &mut data[..];
while rest.len() > 0 {
let chunk_len = 1 + rng(&mut state) % 512;
Expand Down
2 changes: 1 addition & 1 deletion benches/extra/zipslices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a, 'b, A, B> ZipSlices<&'a [A], &'b [B]> {
#[inline(always)]
pub fn new(a: &'a [A], b: &'b [B]) -> Self {
let minl = cmp::min(a.len(), b.len());
ZipSlices {
Self {
t: a,
u: b,
len: minl,
Expand Down
2 changes: 1 addition & 1 deletion examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() {
let irises = DATA
.lines()
.map(str::parse)
.fold_ok(Vec::new(), |mut v, iris: Iris| {
.fold_ok(vec![], |mut v, iris: Iris| {
v.push(iris);
v
});
Expand Down
28 changes: 15 additions & 13 deletions src/adaptors/coalesce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ where
fn next(&mut self) -> Option<Self::Item> {
let Self { iter, last, f } = self;
// this fuses the iterator
let init = match last {
Some(elt) => elt.take(),
None => {
*last = Some(None);
iter.next().map(C::new)
}
}?;
let init =
match last {
Some(elt) => elt.take(),
None => {
*last = Some(None);
iter.next().map(C::new)
}
}?;

Some(
iter.try_fold(init, |accum, next| match f.coalesce_pair(accum, next) {
Expand Down Expand Up @@ -88,12 +89,13 @@ where
mut f,
} = self;
if let Some(last) = last.unwrap_or_else(|| iter.next().map(C::new)) {
let (last, acc) = iter.fold((last, acc), |(last, acc), elt| {
match f.coalesce_pair(last, elt) {
Ok(joined) => (joined, acc),
Err((last_, next_)) => (next_, fn_acc(acc, last_)),
}
});
let (last, acc) =
iter.fold((last, acc), |(last, acc), elt| {
match f.coalesce_pair(last, elt) {
Ok(joined) => (joined, acc),
Err((last_, next_)) => (next_, fn_acc(acc, last_)),
}
});
fn_acc(acc, last)
} else {
acc
Expand Down
13 changes: 7 additions & 6 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ where
let (next_lower, next_upper) = next_hint;
let (combined_lower, combined_upper) =
size_hint::mul_scalar(size_hint::min(curr_hint, next_hint), 2);
let lower = if curr_lower > next_lower {
combined_lower + 1
} else {
combined_lower
};
let lower =
if curr_lower > next_lower {
combined_lower + 1
} else {
combined_lower
};
let upper = {
let extra_elem = match (curr_upper, next_upper) {
(_, None) => false,
Expand Down Expand Up @@ -218,7 +219,7 @@ where
/// Split the `PutBack` into its parts.
#[inline]
pub fn into_parts(self) -> (Option<I::Item>, I) {
let PutBack { top, iter } = self;
let Self { top, iter } = self;
(top, iter)
}

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/multi_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
I::Item: Clone,
{
fn new(iter: I) -> Self {
MultiProductIter {
Self {
cur: None,
iter: iter.clone(),
iter_orig: iter,
Expand Down
6 changes: 3 additions & 3 deletions src/duplicates_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod private {

impl<I: Iterator, Key: Eq + Hash, F> DuplicatesBy<I, Key, F> {
pub(crate) fn new(iter: I, key_method: F) -> Self {
DuplicatesBy {
Self {
iter,
meta: Meta {
used: HashMap::new(),
Expand Down Expand Up @@ -77,7 +77,7 @@ mod private {
type Item = I::Item;

fn next(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.find_map(|v| meta.filter(v))
}

Expand Down Expand Up @@ -109,7 +109,7 @@ mod private {
F: KeyMethod<Key, I::Item>,
{
fn next_back(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.rev().find_map(|v| meta.filter(v))
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/either_or_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ impl<A, B> EitherOrBoth<A, B> {
B: Default,
{
match self {
EitherOrBoth::Left(l) => (l, B::default()),
EitherOrBoth::Right(r) => (A::default(), r),
EitherOrBoth::Both(l, r) => (l, r),
Left(l) => (l, B::default()),
Right(r) => (A::default(), r),
Both(l, r) => (l, r),
}
}

Expand Down Expand Up @@ -503,8 +503,8 @@ impl<T> EitherOrBoth<T, T> {
impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
fn into(self) -> Option<Either<A, B>> {
match self {
EitherOrBoth::Left(l) => Some(Either::Left(l)),
EitherOrBoth::Right(r) => Some(Either::Right(r)),
Left(l) => Some(Either::Left(l)),
Right(r) => Some(Either::Right(r)),
_ => None,
}
}
Expand All @@ -513,8 +513,8 @@ impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
impl<A, B> From<Either<A, B>> for EitherOrBoth<A, B> {
fn from(either: Either<A, B>) -> Self {
match either {
Either::Left(l) => EitherOrBoth::Left(l),
Either::Right(l) => EitherOrBoth::Right(l),
Either::Left(l) => Left(l),
Either::Right(l) => Right(l),
}
}
}
2 changes: 1 addition & 1 deletion src/extrema_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
{
match it.next() {
None => Vec::new(),
None => vec![],
Some(element) => {
let mut current_key = key_for(&element);
let mut result = vec![element];
Expand Down
4 changes: 2 additions & 2 deletions src/free.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
/// ```
/// use itertools::zip;
///
/// let mut result: Vec<(i32, char)> = Vec::new();
/// let mut result: Vec<(i32, char)> = vec![];
///
/// for (a, b) in zip(&[1, 2, 3, 4, 5], &['a', 'b', 'c']) {
/// result.push((*a, *b));
Expand All @@ -139,7 +139,7 @@ where
/// ```
/// use itertools::chain;
///
/// let mut result:Vec<i32> = Vec::new();
/// let mut result:Vec<i32> = vec![];
///
/// for element in chain(&[1, 2, 3], &[4]) {
/// result.push(*element);
Expand Down
10 changes: 5 additions & 5 deletions src/groupbylazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ChunkIndex {
impl ChunkIndex {
#[inline(always)]
fn new(size: usize) -> Self {
ChunkIndex {
Self {
size,
index: 0,
key: 0,
Expand Down Expand Up @@ -163,7 +163,7 @@ where
// Because the `Groups` iterator is always the first to request
// each group index, client is the next index efter top_group.
debug_assert!(self.top_group + 1 == client);
let mut group = Vec::new();
let mut group = vec![];

if let Some(elt) = self.current_elt.take() {
if self.top_group != self.dropped_group {
Expand Down Expand Up @@ -207,7 +207,7 @@ where
self.bottom_group += 1;
self.oldest_buffered_group += 1;
} else {
self.buffer.push(Vec::new().into_iter());
self.buffer.push(vec![].into_iter());
}
}
self.buffer.push(group.into_iter());
Expand Down Expand Up @@ -322,7 +322,7 @@ where
top_group: 0,
oldest_buffered_group: 0,
bottom_group: 0,
buffer: Vec::new(),
buffer: vec![],
dropped_group: !0,
}),
index: Cell::new(0),
Expand Down Expand Up @@ -463,7 +463,7 @@ where
top_group: 0,
oldest_buffered_group: 0,
bottom_group: 0,
buffer: Vec::new(),
buffer: vec![],
dropped_group: !0,
}),
index: Cell::new(0),
Expand Down
11 changes: 3 additions & 8 deletions src/kmerge_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@ where
I: Iterator,
{
/// Constructs a `HeadTail` from an `Iterator`. Returns `None` if the `Iterator` is empty.
fn new(mut it: I) -> Option<HeadTail<I>> {
let head = it.next();
head.map(|h| HeadTail { head: h, tail: it })
fn new(mut it: I) -> Option<Self> {
it.next().map(|h| Self { head: h, tail: it })
}

/// Get the next element and update `head`, returning the old head in `Some`.
///
/// Returns `None` when the tail is exhausted (only `head` then remains).
fn next(&mut self) -> Option<I::Item> {
if let Some(next) = self.tail.next() {
Some(replace(&mut self.head, next))
} else {
None
}
self.tail.next().map(|next| replace(&mut self.head, next))
}

/// Hints at the size of the sequence, same as the `Iterator` method.
Expand Down
6 changes: 3 additions & 3 deletions src/lazy_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ impl<I> LazyBuffer<I>
where
I: Iterator,
{
pub fn new(it: I) -> LazyBuffer<I> {
LazyBuffer {
pub fn new(it: I) -> Self {
Self {
it: it.fuse(),
buffer: Vec::new(),
buffer: vec![],
}
}

Expand Down
Loading
Loading