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

Better sso structures #77171

Merged
merged 5 commits into from
Oct 5, 2020
Merged
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
3 changes: 1 addition & 2 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod frozen;
pub mod mini_map;
pub mod mini_set;
pub mod sso;
pub mod tagged_ptr;
pub mod temp_dir;
pub mod unhash;
Expand Down
61 changes: 0 additions & 61 deletions compiler/rustc_data_structures/src/mini_map.rs

This file was deleted.

41 changes: 0 additions & 41 deletions compiler/rustc_data_structures/src/mini_set.rs

This file was deleted.

75 changes: 75 additions & 0 deletions compiler/rustc_data_structures/src/sso/either_iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::fmt;
use std::iter::ExactSizeIterator;
use std::iter::FusedIterator;
use std::iter::Iterator;

/// Iterator which may contain instance of
/// one of two specific implementations.
///
/// Note: For most methods providing custom
/// implementation may margianlly
/// improve performance by avoiding
/// doing Left/Right match on every step
/// and doing it only once instead.
#[derive(Clone)]
pub enum EitherIter<L, R> {
Left(L),
Right(R),
}

impl<L, R> Iterator for EitherIter<L, R>
where
L: Iterator,
R: Iterator<Item = L::Item>,
{
type Item = L::Item;

fn next(&mut self) -> Option<Self::Item> {
match self {
EitherIter::Left(l) => l.next(),
EitherIter::Right(r) => r.next(),
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
match self {
EitherIter::Left(l) => l.size_hint(),
EitherIter::Right(r) => r.size_hint(),
}
}
}

impl<L, R> ExactSizeIterator for EitherIter<L, R>
where
L: ExactSizeIterator,
R: ExactSizeIterator,
EitherIter<L, R>: Iterator,
{
fn len(&self) -> usize {
match self {
EitherIter::Left(l) => l.len(),
EitherIter::Right(r) => r.len(),
}
}
}

impl<L, R> FusedIterator for EitherIter<L, R>
where
L: FusedIterator,
R: FusedIterator,
EitherIter<L, R>: Iterator,
{
}

impl<L, R> fmt::Debug for EitherIter<L, R>
where
L: fmt::Debug,
R: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EitherIter::Left(l) => l.fmt(f),
EitherIter::Right(r) => r.fmt(f),
}
}
}
Loading