Merge pull request #2559 from mozilla/incoming

Incoming
This commit is contained in:
Patrick Walton 2012-06-08 20:37:57 -07:00
commit 5a04069042
2 changed files with 43 additions and 10 deletions

View File

@ -592,7 +592,22 @@ fn shift_char(&s: str) -> char unsafe {
*/
#[doc = "Bytewise string equality"]
pure fn eq(&&a: str, &&b: str) -> bool { a == b }
pure fn eq(&&a: str, &&b: str) -> bool {
// FIXME: This should just be "a == b" but that calls into the shape code
// :(
let a_len = a.len();
let b_len = b.len();
if a_len != b_len { ret false; }
let mut end = uint::min(a_len, b_len);
let mut i = 0u;
while i < end {
if a[i] != b[i] { ret false; }
i += 1u;
}
ret true;
}
#[doc = "Bytewise less than or equal"]
pure fn le(&&a: str, &&b: str) -> bool { a <= b }
@ -1861,11 +1876,11 @@ fn is_whitespace() -> bool { is_whitespace(self) }
Alphanumeric characters are determined by `char::is_alphanumeric`
"]
#[inlune]
#[inline]
fn is_alphanumeric() -> bool { is_alphanumeric(self) }
#[inline]
#[doc ="Returns the size in bytes not counting the null terminator"]
fn len() -> uint { len(self) }
pure fn len() -> uint { len(self) }
#[doc = "
Returns a slice of the given string from the byte range [`begin`..`end`)

View File

@ -70,7 +70,9 @@ enum class_contents { ctor_decl(fn_decl, blk, codemap::span),
let mut token: token::token;
let mut span: span;
let mut last_span: span;
let buffer: dvec<{tok: token::token, span: span}>;
let mut buffer: [mut {tok: token::token, span: span}]/4;
let mut buffer_start: int;
let mut buffer_end: int;
let mut restriction: restriction;
let reader: reader;
let keywords: hashmap<str, ()>;
@ -86,7 +88,14 @@ enum class_contents { ctor_decl(fn_decl, blk, codemap::span),
self.token = tok0.tok;
self.span = span0;
self.last_span = span0;
self.buffer = dvec::dvec();
self.buffer = [mut
{tok: tok0.tok, span: span0},
{tok: tok0.tok, span: span0},
{tok: tok0.tok, span: span0},
{tok: tok0.tok, span: span0}
]/4;
self.buffer_start = 0;
self.buffer_end = 0;
self.restriction = UNRESTRICTED;
self.reader = rdr;
self.keywords = token::keyword_table();
@ -98,12 +107,13 @@ enum class_contents { ctor_decl(fn_decl, blk, codemap::span),
fn bump() {
self.last_span = self.span;
if self.buffer.len() == 0u {
if self.buffer_start == self.buffer_end {
let next = lexer::next_token(self.reader);
self.token = next.tok;
self.span = mk_sp(next.chpos, self.reader.chpos);
} else {
let next = self.buffer.shift();
let next = self.buffer[self.buffer_start];
self.buffer_start = (self.buffer_start + 1) & 3;
self.token = next.tok;
self.span = next.span;
}
@ -112,13 +122,21 @@ fn swap(next: token::token, lo: uint, hi: uint) {
self.token = next;
self.span = mk_sp(lo, hi);
}
fn buffer_length() -> int {
if self.buffer_start <= self.buffer_end {
ret self.buffer_end - self.buffer_start;
}
ret (4 - self.buffer_start) + self.buffer_end;
}
fn look_ahead(distance: uint) -> token::token {
while self.buffer.len() < distance {
let dist = distance as int;
while self.buffer_length() < dist {
let next = lexer::next_token(self.reader);
let sp = mk_sp(next.chpos, self.reader.chpos);
self.buffer.push({tok: next.tok, span: sp});
self.buffer[self.buffer_end] = {tok: next.tok, span: sp};
self.buffer_end = (self.buffer_end + 1) & 3;
}
ret self.buffer[distance - 1u].tok;
ret copy self.buffer[(self.buffer_start + dist - 1) & 3].tok;
}
fn fatal(m: str) -> ! {
self.sess.span_diagnostic.span_fatal(copy self.span, m)