Skip to content

Commit

Permalink
Ungate par_iter for RangeInclusive<char>
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed Jun 19, 2020
1 parent 51513bc commit 8f37302
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 0 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ fn main() {
if ac.probe_expression("(0..10).step_by(2).rev()") {
autocfg::emit("step_by");
}
if ac.probe_expression("('a'..='z').next()") {
autocfg::emit("iterable_range_char")
}
}
21 changes: 13 additions & 8 deletions src/range_inclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
use crate::iter::plumbing::*;
use crate::iter::*;
use std::ops::RangeInclusive;

#[cfg(iterable_range_char)]
use std::char;
use std::ops::RangeInclusive;

/// Parallel iterator over an inclusive range, implemented for all integer types.
///
Expand Down Expand Up @@ -51,15 +49,25 @@ pub struct Iter<T> {

impl<T> Iter<T>
where
RangeInclusive<T>: Clone + Iterator<Item = T> + DoubleEndedIterator,
RangeInclusive<T>: Eq,
T: Ord + Copy,
{
/// Returns `Some((start, end))` for `start..=end`, or `None` if it is exhausted.
///
/// Note that `RangeInclusive` does not specify the bounds of an exhausted iterator,
/// so this is a way for us to figure out what we've got. Thankfully, all of the
/// integer types we care about can be trivially cloned.
fn bounds(&self) -> Option<(T, T)> {
Some((self.range.clone().next()?, self.range.clone().next_back()?))
let start = *self.range.start();
let end = *self.range.end();
if start <= end && self.range == (start..=end) {
// If the range is still nonempty, this is obviously true
// If the range is exhausted, either start > end or
// the range does not equal start..=end.
Some((start, end))
} else {
None
}
}
}

Expand Down Expand Up @@ -151,7 +159,6 @@ parallel_range_impl! {u128}
parallel_range_impl! {i128}

// char is special
#[cfg(iterable_range_char)]
macro_rules! convert_char {
( $self:ident . $method:ident ( $( $arg:expr ),* ) ) => {
if let Some((start, end)) = $self.bounds() {
Expand All @@ -177,7 +184,6 @@ macro_rules! convert_char {
};
}

#[cfg(iterable_range_char)]
impl ParallelIterator for Iter<char> {
type Item = char;

Expand All @@ -194,7 +200,6 @@ impl ParallelIterator for Iter<char> {
}

// Range<u32> is broken on 16 bit platforms, may as well benefit from it
#[cfg(iterable_range_char)]
impl IndexedParallelIterator for Iter<char> {
// Split at the surrogate range first if we're allowed to
fn drive<C>(self, consumer: C) -> C::Result
Expand Down
1 change: 0 additions & 1 deletion tests/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fn half_open_correctness() {
}

#[test]
#[cfg(iterable_range_char)]
fn closed_correctness() {
let low = char::from_u32(0xD800 - 0x7).unwrap();
let high = char::from_u32(0xE000 + 0x7).unwrap();
Expand Down

0 comments on commit 8f37302

Please sign in to comment.