Skip to content

Commit

Permalink
Refactored code into Searcher traits with naive implementations
Browse files Browse the repository at this point in the history
Made the family of Split iterators use the Pattern API

Renamed the Matcher traits into Searcher
  • Loading branch information
Kimundi committed Feb 19, 2015
1 parent 13ea906 commit f9ef8cd
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 390 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Expand Up @@ -23,7 +23,7 @@
#![feature(env)]
#![feature(core)]

#![deny(warnings)]
// #![deny(warnings)]

extern crate test;
extern crate getopts;
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/str.rs
Expand Up @@ -706,7 +706,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[unstable(feature = "collections",
reason = "might have its iterator type changed")]
fn match_indices<'a>(&'a self, pat: &'a str) -> MatchIndices<'a> {
fn match_indices<'a, 'b>(&'a self, pat: &'b str) -> MatchIndices<'a, &'b str> {
core_str::StrExt::match_indices(&self[..], pat)
}

Expand All @@ -723,7 +723,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[unstable(feature = "collections",
reason = "might get removed in the future in favor of a more generic split()")]
fn split_str<'a>(&'a self, pat: &'a str) -> SplitStr<'a> {
fn split_str<'a, 'b>(&'a self, pat: &'b str) -> SplitStr<'a, &'b str> {
core_str::StrExt::split_str(&self[..], pat)
}

Expand Down
27 changes: 15 additions & 12 deletions src/libcore/char.rs
Expand Up @@ -22,13 +22,13 @@ use option::Option;
use slice::SliceExt;

// UTF-8 ranges and tags for encoding characters
static TAG_CONT: u8 = 0b1000_0000u8;
static TAG_TWO_B: u8 = 0b1100_0000u8;
static TAG_THREE_B: u8 = 0b1110_0000u8;
static TAG_FOUR_B: u8 = 0b1111_0000u8;
static MAX_ONE_B: u32 = 0x80u32;
static MAX_TWO_B: u32 = 0x800u32;
static MAX_THREE_B: u32 = 0x10000u32;
const TAG_CONT: u8 = 0b1000_0000u8;
const TAG_TWO_B: u8 = 0b1100_0000u8;
const TAG_THREE_B: u8 = 0b1110_0000u8;
const TAG_FOUR_B: u8 = 0b1111_0000u8;
const MAX_ONE_B: u32 = 0x80u32;
const MAX_TWO_B: u32 = 0x800u32;
const MAX_THREE_B: u32 = 0x10000u32;

/*
Lu Uppercase_Letter an uppercase letter
Expand Down Expand Up @@ -398,11 +398,14 @@ impl CharExt for char {
#[stable(feature = "rust1", since = "1.0.0")]
fn len_utf8(self) -> usize {
let code = self as u32;
match () {
_ if code < MAX_ONE_B => 1,
_ if code < MAX_TWO_B => 2,
_ if code < MAX_THREE_B => 3,
_ => 4,
if code < MAX_ONE_B {
1
} else if code < MAX_TWO_B {
2
} else if code < MAX_THREE_B {
3
} else {
4
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/libcore/slice.rs
Expand Up @@ -657,6 +657,8 @@ macro_rules! iterator {
fn next(&mut self) -> Option<$elem> {
// could be implemented with slices, but this avoids bounds checks
unsafe {
::intrinsics::assume(!self.ptr.is_null());
::intrinsics::assume(!self.end.is_null());
if self.ptr == self.end {
None
} else {
Expand Down Expand Up @@ -693,6 +695,8 @@ macro_rules! iterator {
fn next_back(&mut self) -> Option<$elem> {
// could be implemented with slices, but this avoids bounds checks
unsafe {
::intrinsics::assume(!self.ptr.is_null());
::intrinsics::assume(!self.end.is_null());
if self.end == self.ptr {
None
} else {
Expand Down

0 comments on commit f9ef8cd

Please sign in to comment.