alacritty

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit eb7a1ea803ba54d3b8cd6af49255eb8fbe0d7544
parent fc28e49c277f777dbced6cbfeccb106c04486f15
Author: Christian Duerr <chrisduerr@users.noreply.github.com>
Date:   Sun, 17 Mar 2019 21:09:27 +0000

Remove InclusiveRange code

This removes all inclusive range code since it has been recently
stabilized in the standard lib.
Diffstat:
Msrc/index.rs | 90++-----------------------------------------------------------------------------
Msrc/renderer/mod.rs | 4++--
Msrc/term/mod.rs | 4++--
3 files changed, 6 insertions(+), 92 deletions(-)

diff --git a/src/index.rs b/src/index.rs @@ -17,7 +17,7 @@ /// Indexing types and implementations for Grid and Line use std::cmp::{Ord, Ordering}; use std::fmt; -use std::ops::{self, Deref, Add, Range}; +use std::ops::{self, Deref, Add, Range, RangeInclusive}; /// The side of a cell #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -228,88 +228,6 @@ impl<T> From<Range<T>> for IndexRange<T> { } } -pub enum RangeInclusive<Idx> { - Empty { - at: Idx, - }, - NonEmpty { - start: Idx, - end: Idx, - }, -} - -impl<Idx> RangeInclusive<Idx> { - pub fn new(from: Idx, to: Idx) -> Self { - RangeInclusive::NonEmpty { - start: from, - end: to - } - } -} - -macro_rules! inclusive { - ($ty:ty, $steps_add_one:expr) => { - // impl copied from stdlib, can be removed when inclusive_range is stabilized - impl Iterator for RangeInclusive<$ty> { - type Item = $ty; - - #[inline] - fn next(&mut self) -> Option<$ty> { - use crate::index::RangeInclusive::*; - - match *self { - Empty { .. } => None, // empty iterators yield no values - - NonEmpty { ref mut start, ref mut end } => { - - // march start towards (maybe past!) end and yield the old value - if start <= end { - let old = *start; - *start = old + 1; - Some(old) - } else { - *self = Empty { at: *end }; - None - } - } - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option<usize>) { - use crate::index::RangeInclusive::*; - - match *self { - Empty { .. } => (0, Some(0)), - - NonEmpty { start, end } => { - let added = $steps_add_one(start, end); - match added { - Some(hint) => (hint.saturating_add(1), hint.checked_add(1)), - None => (0, None) - } - } - } - } - } - } -} - -fn steps_add_one_u8(start: u8, end: u8) -> Option<usize> { - if start < end { - Some((end - start) as usize) - } else { - None - } -} -inclusive!(u8, steps_add_one_u8); - -#[test] -fn test_range() { - assert_eq!(RangeInclusive::new(1,10).collect::<Vec<_>>(), - vec![1,2,3,4,5,6,7,8,9,10]); -} - // can be removed if range_contains is stabilized pub trait Contains { type Content; @@ -326,9 +244,7 @@ impl<T: PartialOrd<T>> Contains for Range<T> { impl<T: PartialOrd<T>> Contains for RangeInclusive<T> { type Content = T; fn contains_(&self, item: Self::Content) -> bool { - if let RangeInclusive::NonEmpty{ref start, ref end} = *self { - (*start <= item) && (item <= *end) - } else { false } + (self.start() <= &item) && (&item <= self.end()) } } @@ -384,8 +300,6 @@ macro_rules! ops { } } - inclusive!($ty, <$ty>::steps_between_by_one); - impl DoubleEndedIterator for IndexRange<$ty> { #[inline] fn next_back(&mut self) -> Option<$ty> { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs @@ -28,7 +28,7 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use crate::gl::types::*; use crate::gl; -use crate::index::{Column, Line, RangeInclusive}; +use crate::index::{Column, Line}; use crate::term::color::Rgb; use crate::config::{self, Config, Delta}; use crate::term::{self, cell, RenderableCell}; @@ -213,7 +213,7 @@ impl GlyphCache { fn load_glyphs_for_font<L: LoadGlyph>(&mut self, font: FontKey, loader: &mut L) { let size = self.font_size; - for i in RangeInclusive::new(32u8, 128u8) { + for i in 32u8..=128u8 { self.get(GlyphKey { font_key: font, c: i as char, diff --git a/src/term/mod.rs b/src/term/mod.rs @@ -13,7 +13,7 @@ // limitations under the License. // //! Exports the `Term` type which is a high-level API for the Grid -use std::ops::{Range, Index, IndexMut}; +use std::ops::{Range, Index, IndexMut, RangeInclusive}; use std::{ptr, io, mem}; use std::cmp::{min, max}; use std::time::{Duration, Instant}; @@ -27,7 +27,7 @@ use crate::grid::{ BidirectionalIterator, DisplayIter, Grid, GridCell, IndexRegion, Indexed, Scroll, ViewportPosition, }; -use crate::index::{self, Point, Column, Line, IndexRange, Contains, RangeInclusive, Linear}; +use crate::index::{self, Point, Column, Line, IndexRange, Contains, Linear}; use crate::selection::{self, Selection, Locations}; use crate::config::{Config, VisualBellAnimation}; use crate::MouseCursor;