libsyntax: remove unnecessary as_slice()
calls
This commit is contained in:
parent
60338d91c4
commit
39f44c0c20
7 changed files with 22 additions and 24 deletions
|
@ -260,7 +260,7 @@ impl<'ast> Map<'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
|
fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
|
||||||
self.map.borrow().as_slice().get(id as uint).map(|e| *e)
|
self.map.borrow().get(id as uint).map(|e| *e)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(&self) -> &'ast Crate {
|
pub fn krate(&self) -> &'ast Crate {
|
||||||
|
|
|
@ -290,7 +290,7 @@ impl FileMap {
|
||||||
lines.get(line_number).map(|&line| {
|
lines.get(line_number).map(|&line| {
|
||||||
let begin: BytePos = line - self.start_pos;
|
let begin: BytePos = line - self.start_pos;
|
||||||
let begin = begin.to_uint();
|
let begin = begin.to_uint();
|
||||||
let slice = self.src.as_slice().slice_from(begin);
|
let slice = self.src.slice_from(begin);
|
||||||
match slice.find('\n') {
|
match slice.find('\n') {
|
||||||
Some(e) => slice.slice_to(e),
|
Some(e) => slice.slice_to(e),
|
||||||
None => slice
|
None => slice
|
||||||
|
@ -308,8 +308,8 @@ impl FileMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_real_file(&self) -> bool {
|
pub fn is_real_file(&self) -> bool {
|
||||||
!(self.name.as_slice().starts_with("<") &&
|
!(self.name.starts_with("<") &&
|
||||||
self.name.as_slice().ends_with(">"))
|
self.name.ends_with(">"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,8 +336,8 @@ impl CodeMap {
|
||||||
// Remove utf-8 BOM if any.
|
// Remove utf-8 BOM if any.
|
||||||
// FIXME #12884: no efficient/safe way to remove from the start of a string
|
// FIXME #12884: no efficient/safe way to remove from the start of a string
|
||||||
// and reuse the allocation.
|
// and reuse the allocation.
|
||||||
let mut src = if src.as_slice().starts_with("\ufeff") {
|
let mut src = if src.starts_with("\ufeff") {
|
||||||
String::from_str(src.as_slice().slice_from(3))
|
String::from_str(src.slice_from(3))
|
||||||
} else {
|
} else {
|
||||||
String::from_str(src.as_slice())
|
String::from_str(src.as_slice())
|
||||||
};
|
};
|
||||||
|
@ -346,7 +346,7 @@ impl CodeMap {
|
||||||
// This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally
|
// This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally
|
||||||
// overflowing into the next filemap in case the last byte of span is also the last
|
// overflowing into the next filemap in case the last byte of span is also the last
|
||||||
// byte of filemap, which leads to incorrect results from CodeMap.span_to_*.
|
// byte of filemap, which leads to incorrect results from CodeMap.span_to_*.
|
||||||
if src.len() > 0 && !src.as_slice().ends_with("\n") {
|
if src.len() > 0 && !src.ends_with("\n") {
|
||||||
src.push('\n');
|
src.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,14 +426,14 @@ impl CodeMap {
|
||||||
if begin.fm.start_pos != end.fm.start_pos {
|
if begin.fm.start_pos != end.fm.start_pos {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(begin.fm.src.as_slice().slice(begin.pos.to_uint(),
|
Some(begin.fm.src.slice(begin.pos.to_uint(),
|
||||||
end.pos.to_uint()).to_string())
|
end.pos.to_uint()).to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_filemap(&self, filename: &str) -> Rc<FileMap> {
|
pub fn get_filemap(&self, filename: &str) -> Rc<FileMap> {
|
||||||
for fm in self.files.borrow().iter() {
|
for fm in self.files.borrow().iter() {
|
||||||
if filename == fm.name.as_slice() {
|
if filename == fm.name {
|
||||||
return fm.clone();
|
return fm.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -527,7 +527,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
let mut call_site = None;
|
let mut call_site = None;
|
||||||
loop {
|
loop {
|
||||||
let expn_info = self.codemap().with_expn_info(expn_id, |ei| {
|
let expn_info = self.codemap().with_expn_info(expn_id, |ei| {
|
||||||
ei.map(|ei| (ei.call_site, ei.callee.name.as_slice() == "include"))
|
ei.map(|ei| (ei.call_site, ei.callee.name == "include"))
|
||||||
});
|
});
|
||||||
match expn_info {
|
match expn_info {
|
||||||
None => break,
|
None => break,
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_feature(&self, feature: &str) -> bool {
|
fn has_feature(&self, feature: &str) -> bool {
|
||||||
self.features.iter().any(|n| n.as_slice() == feature)
|
self.features.iter().any(|&n| n == feature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,21 +66,20 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
|
||||||
let mut j = lines.len();
|
let mut j = lines.len();
|
||||||
// first line of all-stars should be omitted
|
// first line of all-stars should be omitted
|
||||||
if lines.len() > 0 &&
|
if lines.len() > 0 &&
|
||||||
lines[0].as_slice().chars().all(|c| c == '*') {
|
lines[0].chars().all(|c| c == '*') {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
while i < j && lines[i].as_slice().trim().is_empty() {
|
while i < j && lines[i].trim().is_empty() {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
// like the first, a last line of all stars should be omitted
|
// like the first, a last line of all stars should be omitted
|
||||||
if j > i && lines[j - 1]
|
if j > i && lines[j - 1]
|
||||||
.as_slice()
|
|
||||||
.chars()
|
.chars()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.all(|c| c == '*') {
|
.all(|c| c == '*') {
|
||||||
j -= 1;
|
j -= 1;
|
||||||
}
|
}
|
||||||
while j > i && lines[j - 1].as_slice().trim().is_empty() {
|
while j > i && lines[j - 1].trim().is_empty() {
|
||||||
j -= 1;
|
j -= 1;
|
||||||
}
|
}
|
||||||
return lines.slice(i, j).iter().map(|x| (*x).clone()).collect();
|
return lines.slice(i, j).iter().map(|x| (*x).clone()).collect();
|
||||||
|
@ -92,7 +91,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
|
||||||
let mut can_trim = true;
|
let mut can_trim = true;
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for line in lines.iter() {
|
for line in lines.iter() {
|
||||||
for (j, c) in line.as_slice().chars().enumerate() {
|
for (j, c) in line.chars().enumerate() {
|
||||||
if j > i || !"* \t".contains_char(c) {
|
if j > i || !"* \t".contains_char(c) {
|
||||||
can_trim = false;
|
can_trim = false;
|
||||||
break;
|
break;
|
||||||
|
@ -117,7 +116,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
|
||||||
|
|
||||||
if can_trim {
|
if can_trim {
|
||||||
lines.iter().map(|line| {
|
lines.iter().map(|line| {
|
||||||
line.as_slice().slice(i + 1, line.len()).to_string()
|
line.slice(i + 1, line.len()).to_string()
|
||||||
}).collect()
|
}).collect()
|
||||||
} else {
|
} else {
|
||||||
lines
|
lines
|
||||||
|
@ -228,7 +227,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String> ,
|
||||||
let s1 = match all_whitespace(s.as_slice(), col) {
|
let s1 = match all_whitespace(s.as_slice(), col) {
|
||||||
Some(col) => {
|
Some(col) => {
|
||||||
if col < len {
|
if col < len {
|
||||||
s.as_slice().slice(col, len).to_string()
|
s.slice(col, len).to_string()
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
|
@ -265,7 +264,7 @@ fn read_block_comment(rdr: &mut StringReader,
|
||||||
if is_block_doc_comment(curr_line.as_slice()) {
|
if is_block_doc_comment(curr_line.as_slice()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert!(!curr_line.as_slice().contains_char('\n'));
|
assert!(!curr_line.contains_char('\n'));
|
||||||
lines.push(curr_line);
|
lines.push(curr_line);
|
||||||
} else {
|
} else {
|
||||||
let mut level: int = 1;
|
let mut level: int = 1;
|
||||||
|
|
|
@ -265,7 +265,7 @@ impl<'a> StringReader<'a> {
|
||||||
/// Calls `f` with a string slice of the source text spanning from `start`
|
/// Calls `f` with a string slice of the source text spanning from `start`
|
||||||
/// up to but excluding `end`.
|
/// up to but excluding `end`.
|
||||||
fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T {
|
fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T {
|
||||||
f(self.filemap.src.as_slice().slice(
|
f(self.filemap.src.slice(
|
||||||
self.byte_offset(start).to_uint(),
|
self.byte_offset(start).to_uint(),
|
||||||
self.byte_offset(end).to_uint()))
|
self.byte_offset(end).to_uint()))
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,6 @@ impl<'a> StringReader<'a> {
|
||||||
let last_char = self.curr.unwrap();
|
let last_char = self.curr.unwrap();
|
||||||
let next = self.filemap
|
let next = self.filemap
|
||||||
.src
|
.src
|
||||||
.as_slice()
|
|
||||||
.char_range_at(current_byte_offset);
|
.char_range_at(current_byte_offset);
|
||||||
let byte_offset_diff = next.next - current_byte_offset;
|
let byte_offset_diff = next.next - current_byte_offset;
|
||||||
self.pos = self.pos + Pos::from_uint(byte_offset_diff);
|
self.pos = self.pos + Pos::from_uint(byte_offset_diff);
|
||||||
|
@ -343,7 +342,7 @@ impl<'a> StringReader<'a> {
|
||||||
pub fn nextch(&self) -> Option<char> {
|
pub fn nextch(&self) -> Option<char> {
|
||||||
let offset = self.byte_offset(self.pos).to_uint();
|
let offset = self.byte_offset(self.pos).to_uint();
|
||||||
if offset < self.filemap.src.len() {
|
if offset < self.filemap.src.len() {
|
||||||
Some(self.filemap.src.as_slice().char_at(offset))
|
Some(self.filemap.src.char_at(offset))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -2844,7 +2844,7 @@ impl<'a> State<'a> {
|
||||||
comments::BlankLine => {
|
comments::BlankLine => {
|
||||||
// We need to do at least one, possibly two hardbreaks.
|
// We need to do at least one, possibly two hardbreaks.
|
||||||
let is_semi = match self.s.last_token() {
|
let is_semi = match self.s.last_token() {
|
||||||
pp::String(s, _) => ";" == s.as_slice(),
|
pp::String(s, _) => ";" == s,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
if is_semi || self.is_begin() || self.is_end() {
|
if is_semi || self.is_begin() || self.is_end() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue