Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
39f44c0c
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
39f44c0c
编写于
11月 27, 2014
作者:
J
Jorge Aparicio
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libsyntax: remove unnecessary `as_slice()` calls
上级
60338d91
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
22 addition
and
24 deletion
+22
-24
src/libsyntax/ast_map/mod.rs
src/libsyntax/ast_map/mod.rs
+1
-1
src/libsyntax/codemap.rs
src/libsyntax/codemap.rs
+9
-9
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+1
-1
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+1
-1
src/libsyntax/parse/lexer/comments.rs
src/libsyntax/parse/lexer/comments.rs
+7
-8
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/mod.rs
+2
-3
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+1
-1
未找到文件。
src/libsyntax/ast_map/mod.rs
浏览文件 @
39f44c0c
...
...
@@ -260,7 +260,7 @@ fn entry_count(&self) -> uint {
}
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
{
...
...
src/libsyntax/codemap.rs
浏览文件 @
39f44c0c
...
...
@@ -290,7 +290,7 @@ pub fn get_line(&self, line_number: uint) -> Option<String> {
lines
.get
(
line_number
)
.map
(|
&
line
|
{
let
begin
:
BytePos
=
line
-
self
.start_pos
;
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'
)
{
Some
(
e
)
=>
slice
.slice_to
(
e
),
None
=>
slice
...
...
@@ -308,8 +308,8 @@ pub fn record_multibyte_char(&self, pos: BytePos, bytes: uint) {
}
pub
fn
is_real_file
(
&
self
)
->
bool
{
!
(
self
.name
.
as_slice
()
.
starts_with
(
"<"
)
&&
self
.name
.
as_slice
()
.
ends_with
(
">"
))
!
(
self
.name
.starts_with
(
"<"
)
&&
self
.name
.ends_with
(
">"
))
}
}
...
...
@@ -336,8 +336,8 @@ pub fn new_filemap(&self, filename: FileName, src: String) -> Rc<FileMap> {
// Remove utf-8 BOM if any.
// FIXME #12884: no efficient/safe way to remove from the start of a string
// and reuse the allocation.
let
mut
src
=
if
src
.
as_slice
()
.
starts_with
(
"
\ufeff
"
)
{
String
::
from_str
(
src
.
as_slice
()
.
slice_from
(
3
))
let
mut
src
=
if
src
.starts_with
(
"
\ufeff
"
)
{
String
::
from_str
(
src
.slice_from
(
3
))
}
else
{
String
::
from_str
(
src
.as_slice
())
};
...
...
@@ -346,7 +346,7 @@ pub fn new_filemap(&self, filename: FileName, src: String) -> Rc<FileMap> {
// 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
// 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'
);
}
...
...
@@ -426,14 +426,14 @@ pub fn span_to_snippet(&self, sp: Span) -> Option<String> {
if
begin
.fm.start_pos
!=
end
.fm.start_pos
{
None
}
else
{
Some
(
begin
.fm.src
.
as_slice
()
.
slice
(
begin
.pos
.to_uint
(),
end
.pos
.to_uint
())
.to_string
())
Some
(
begin
.fm.src
.slice
(
begin
.pos
.to_uint
(),
end
.pos
.to_uint
())
.to_string
())
}
}
pub
fn
get_filemap
(
&
self
,
filename
:
&
str
)
->
Rc
<
FileMap
>
{
for
fm
in
self
.files
.borrow
()
.iter
()
{
if
filename
==
fm
.name
.as_slice
()
{
if
filename
==
fm
.name
{
return
fm
.clone
();
}
}
...
...
src/libsyntax/ext/base.rs
浏览文件 @
39f44c0c
...
...
@@ -527,7 +527,7 @@ pub fn original_span_in_file(&self) -> Span {
let
mut
call_site
=
None
;
loop
{
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
{
None
=>
break
,
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
39f44c0c
...
...
@@ -132,7 +132,7 @@ fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
}
fn
has_feature
(
&
self
,
feature
:
&
str
)
->
bool
{
self
.features
.iter
()
.any
(|
n
|
n
.as_slice
()
==
feature
)
self
.features
.iter
()
.any
(|
&
n
|
n
==
feature
)
}
}
...
...
src/libsyntax/parse/lexer/comments.rs
浏览文件 @
39f44c0c
...
...
@@ -66,21 +66,20 @@ fn vertical_trim(lines: Vec<String> ) -> Vec<String> {
let
mut
j
=
lines
.len
();
// first line of all-stars should be omitted
if
lines
.len
()
>
0
&&
lines
[
0
]
.
as_slice
()
.
chars
()
.all
(|
c
|
c
==
'*'
)
{
lines
[
0
]
.chars
()
.all
(|
c
|
c
==
'*'
)
{
i
+=
1
;
}
while
i
<
j
&&
lines
[
i
]
.
as_slice
()
.
trim
()
.is_empty
()
{
while
i
<
j
&&
lines
[
i
]
.trim
()
.is_empty
()
{
i
+=
1
;
}
// like the first, a last line of all stars should be omitted
if
j
>
i
&&
lines
[
j
-
1
]
.as_slice
()
.chars
()
.skip
(
1
)
.all
(|
c
|
c
==
'*'
)
{
j
-=
1
;
}
while
j
>
i
&&
lines
[
j
-
1
]
.
as_slice
()
.
trim
()
.is_empty
()
{
while
j
>
i
&&
lines
[
j
-
1
]
.trim
()
.is_empty
()
{
j
-=
1
;
}
return
lines
.slice
(
i
,
j
)
.iter
()
.map
(|
x
|
(
*
x
)
.clone
())
.collect
();
...
...
@@ -92,7 +91,7 @@ fn horizontal_trim(lines: Vec<String> ) -> Vec<String> {
let
mut
can_trim
=
true
;
let
mut
first
=
true
;
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
)
{
can_trim
=
false
;
break
;
...
...
@@ -117,7 +116,7 @@ fn horizontal_trim(lines: Vec<String> ) -> Vec<String> {
if
can_trim
{
lines
.iter
()
.map
(|
line
|
{
line
.
as_slice
()
.
slice
(
i
+
1
,
line
.len
())
.to_string
()
line
.slice
(
i
+
1
,
line
.len
())
.to_string
()
})
.collect
()
}
else
{
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
)
{
Some
(
col
)
=>
{
if
col
<
len
{
s
.
as_slice
()
.
slice
(
col
,
len
)
.to_string
()
s
.slice
(
col
,
len
)
.to_string
()
}
else
{
""
.to_string
()
}
...
...
@@ -265,7 +264,7 @@ fn read_block_comment(rdr: &mut StringReader,
if
is_block_doc_comment
(
curr_line
.as_slice
())
{
return
}
assert
!
(
!
curr_line
.
as_slice
()
.
contains_char
(
'\n'
));
assert
!
(
!
curr_line
.contains_char
(
'\n'
));
lines
.push
(
curr_line
);
}
else
{
let
mut
level
:
int
=
1
;
...
...
src/libsyntax/parse/lexer/mod.rs
浏览文件 @
39f44c0c
...
...
@@ -265,7 +265,7 @@ pub fn name_from_to(&self, start: BytePos, end: BytePos) -> ast::Name {
/// Calls `f` with a string slice of the source text spanning from `start`
/// up to but excluding `end`.
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
(
end
)
.to_uint
()))
}
...
...
@@ -321,7 +321,6 @@ pub fn bump(&mut self) {
let
last_char
=
self
.curr
.unwrap
();
let
next
=
self
.filemap
.src
.as_slice
()
.char_range_at
(
current_byte_offset
);
let
byte_offset_diff
=
next
.next
-
current_byte_offset
;
self
.pos
=
self
.pos
+
Pos
::
from_uint
(
byte_offset_diff
);
...
...
@@ -343,7 +342,7 @@ pub fn bump(&mut self) {
pub
fn
nextch
(
&
self
)
->
Option
<
char
>
{
let
offset
=
self
.byte_offset
(
self
.pos
)
.to_uint
();
if
offset
<
self
.filemap.src
.len
()
{
Some
(
self
.filemap.src
.
as_slice
()
.
char_at
(
offset
))
Some
(
self
.filemap.src
.char_at
(
offset
))
}
else
{
None
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
39f44c0c
...
...
@@ -2844,7 +2844,7 @@ pub fn print_comment(&mut self,
comments
::
BlankLine
=>
{
// We need to do at least one, possibly two hardbreaks.
let
is_semi
=
match
self
.s
.last_token
()
{
pp
::
String
(
s
,
_
)
=>
";"
==
s
.as_slice
()
,
pp
::
String
(
s
,
_
)
=>
";"
==
s
,
_
=>
false
};
if
is_semi
||
self
.is_begin
()
||
self
.is_end
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录