Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5a240588
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,发现更多精彩内容 >>
提交
5a240588
编写于
11月 27, 2014
作者:
J
Jorge Aparicio
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libcollections: remove unnecessary `as_mut_slice()` calls
上级
a0621f8e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
32 deletion
+32
-32
src/libcollections/binary_heap.rs
src/libcollections/binary_heap.rs
+1
-1
src/libcollections/btree/node.rs
src/libcollections/btree/node.rs
+8
-8
src/libcollections/slice.rs
src/libcollections/slice.rs
+17
-17
src/libcollections/vec.rs
src/libcollections/vec.rs
+6
-6
未找到文件。
src/libcollections/binary_heap.rs
浏览文件 @
5a240588
...
...
@@ -485,7 +485,7 @@ pub fn into_sorted_vec(self) -> Vec<T> {
let
mut
end
=
q
.len
();
while
end
>
1
{
end
-=
1
;
q
.data
.
as_mut_slice
()
.
swap
(
0
,
end
);
q
.data
.swap
(
0
,
end
);
q
.siftdown_range
(
0
,
end
)
}
q
.into_vec
()
...
...
src/libcollections/btree/node.rs
浏览文件 @
5a240588
...
...
@@ -158,13 +158,13 @@ pub fn is_full(&self) -> bool {
/// Swap the given key-value pair with the key-value pair stored in the node's index,
/// without checking bounds.
pub
unsafe
fn
unsafe_swap
(
&
mut
self
,
index
:
uint
,
key
:
&
mut
K
,
val
:
&
mut
V
)
{
mem
::
swap
(
self
.keys
.
as_mut_slice
()
.
unsafe_mut
(
index
),
key
);
mem
::
swap
(
self
.vals
.
as_mut_slice
()
.
unsafe_mut
(
index
),
val
);
mem
::
swap
(
self
.keys
.unsafe_mut
(
index
),
key
);
mem
::
swap
(
self
.vals
.unsafe_mut
(
index
),
val
);
}
/// Get the node's key mutably without any bounds checks.
pub
unsafe
fn
unsafe_key_mut
(
&
mut
self
,
index
:
uint
)
->
&
mut
K
{
self
.keys
.
as_mut_slice
()
.
unsafe_mut
(
index
)
self
.keys
.unsafe_mut
(
index
)
}
/// Get the node's value at the given index
...
...
@@ -189,12 +189,12 @@ pub fn edge(&self, index: uint) -> Option<&Node<K,V>> {
/// Get the node's edge mutably at the given index
pub
fn
edge_mut
(
&
mut
self
,
index
:
uint
)
->
Option
<&
mut
Node
<
K
,
V
>>
{
self
.edges
.
as_mut_slice
()
.
get_mut
(
index
)
self
.edges
.get_mut
(
index
)
}
/// Get the node's edge mutably without any bounds checks.
pub
unsafe
fn
unsafe_edge_mut
(
&
mut
self
,
index
:
uint
)
->
&
mut
Node
<
K
,
V
>
{
self
.edges
.
as_mut_slice
()
.
unsafe_mut
(
index
)
self
.edges
.unsafe_mut
(
index
)
}
/// Pop an edge off the end of the node
...
...
@@ -292,8 +292,8 @@ pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> {
pub
fn
iter_mut
<
'a
>
(
&
'a
mut
self
)
->
MutTraversal
<
'a
,
K
,
V
>
{
let
is_leaf
=
self
.is_leaf
();
MutTraversal
{
elems
:
self
.keys
.iter
()
.zip
(
self
.vals
.
as_mut_slice
()
.
iter_mut
()),
edges
:
self
.edges
.
as_mut_slice
()
.
iter_mut
(),
elems
:
self
.keys
.iter
()
.zip
(
self
.vals
.iter_mut
()),
edges
:
self
.edges
.iter_mut
(),
head_is_edge
:
true
,
tail_is_edge
:
true
,
has_edges
:
!
is_leaf
,
...
...
@@ -478,7 +478,7 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> {
let
mut
right
=
Vec
::
with_capacity
(
left
.capacity
());
unsafe
{
let
left_ptr
=
left
.unsafe_get
(
left_len
)
as
*
const
_
;
let
right_ptr
=
right
.as_mut_
slice
()
.as_mut_
ptr
();
let
right_ptr
=
right
.as_mut_ptr
();
ptr
::
copy_nonoverlapping_memory
(
right_ptr
,
left_ptr
,
right_len
);
left
.set_len
(
left_len
);
right
.set_len
(
right_len
);
...
...
src/libcollections/slice.rs
浏览文件 @
5a240588
...
...
@@ -201,7 +201,7 @@ fn new_pos(i: uint, s: Direction) -> uint {
match
max
{
Some
((
i
,
sd
))
=>
{
let
j
=
new_pos
(
i
,
sd
.dir
);
self
.sdir
.
as_mut_slice
()
.
swap
(
i
,
j
);
self
.sdir
.swap
(
i
,
j
);
// Swap the direction of each larger SizeDirection
for
x
in
self
.sdir
.iter_mut
()
{
...
...
@@ -256,7 +256,7 @@ fn next(&mut self) -> Option<Vec<T>> {
Some
((
0
,
0
))
=>
Some
(
self
.v
.clone
()),
Some
((
a
,
b
))
=>
{
let
elt
=
self
.v
.clone
();
self
.v
.
as_mut_slice
()
.
swap
(
a
,
b
);
self
.v
.swap
(
a
,
b
);
Some
(
elt
)
}
}
...
...
@@ -779,11 +779,11 @@ fn test_head() {
#[test]
fn
test_head_mut
()
{
let
mut
a
=
vec!
[];
assert_eq!
(
a
.
as_mut_slice
()
.
head_mut
(),
None
);
assert_eq!
(
a
.head_mut
(),
None
);
a
=
vec!
[
11
i
];
assert_eq!
(
*
a
.
as_mut_slice
()
.
head_mut
()
.unwrap
(),
11
);
assert_eq!
(
*
a
.head_mut
()
.unwrap
(),
11
);
a
=
vec!
[
11
i
,
12
];
assert_eq!
(
*
a
.
as_mut_slice
()
.
head_mut
()
.unwrap
(),
11
);
assert_eq!
(
*
a
.head_mut
()
.unwrap
(),
11
);
}
#[test]
...
...
@@ -800,10 +800,10 @@ fn test_tail() {
fn
test_tail_mut
()
{
let
mut
a
=
vec!
[
11
i
];
let
b
:
&
mut
[
int
]
=
&
mut
[];
assert
!
(
a
.
as_mut_slice
()
.
tail_mut
()
==
b
);
assert
!
(
a
.tail_mut
()
==
b
);
a
=
vec!
[
11
i
,
12
];
let
b
:
&
mut
[
int
]
=
&
mut
[
12
];
assert
!
(
a
.
as_mut_slice
()
.
tail_mut
()
==
b
);
assert
!
(
a
.tail_mut
()
==
b
);
}
#[test]
...
...
@@ -817,7 +817,7 @@ fn test_tail_empty() {
#[should_fail]
fn
test_tail_mut_empty
()
{
let
mut
a
:
Vec
<
int
>
=
vec!
[];
a
.
as_mut_slice
()
.
tail_mut
();
a
.tail_mut
();
}
#[test]
...
...
@@ -834,10 +834,10 @@ fn test_init() {
fn
test_init_mut
()
{
let
mut
a
=
vec!
[
11
i
];
let
b
:
&
mut
[
int
]
=
&
mut
[];
assert
!
(
a
.
as_mut_slice
()
.
init_mut
()
==
b
);
assert
!
(
a
.init_mut
()
==
b
);
a
=
vec!
[
11
i
,
12
];
let
b
:
&
mut
[
int
]
=
&
mut
[
11
];
assert
!
(
a
.
as_mut_slice
()
.
init_mut
()
==
b
);
assert
!
(
a
.init_mut
()
==
b
);
}
#[test]
...
...
@@ -851,7 +851,7 @@ fn test_init_empty() {
#[should_fail]
fn
test_init_mut_empty
()
{
let
mut
a
:
Vec
<
int
>
=
vec!
[];
a
.
as_mut_slice
()
.
init_mut
();
a
.init_mut
();
}
#[test]
...
...
@@ -867,11 +867,11 @@ fn test_last() {
#[test]
fn
test_last_mut
()
{
let
mut
a
=
vec!
[];
assert_eq!
(
a
.
as_mut_slice
()
.
last_mut
(),
None
);
assert_eq!
(
a
.last_mut
(),
None
);
a
=
vec!
[
11
i
];
assert_eq!
(
*
a
.
as_mut_slice
()
.
last_mut
()
.unwrap
(),
11
);
assert_eq!
(
*
a
.last_mut
()
.unwrap
(),
11
);
a
=
vec!
[
11
i
,
12
];
assert_eq!
(
*
a
.
as_mut_slice
()
.
last_mut
()
.unwrap
(),
12
);
assert_eq!
(
*
a
.last_mut
()
.unwrap
(),
12
);
}
#[test]
...
...
@@ -1299,13 +1299,13 @@ fn test_sort() {
.collect
::
<
Vec
<
uint
>>
();
let
mut
v1
=
v
.clone
();
v
.
as_mut_slice
()
.
sort
();
v
.sort
();
assert
!
(
v
.as_slice
()
.windows
(
2
)
.all
(|
w
|
w
[
0
]
<=
w
[
1
]));
v1
.
as_mut_slice
()
.
sort_by
(|
a
,
b
|
a
.cmp
(
b
));
v1
.sort_by
(|
a
,
b
|
a
.cmp
(
b
));
assert
!
(
v1
.as_slice
()
.windows
(
2
)
.all
(|
w
|
w
[
0
]
<=
w
[
1
]));
v1
.
as_mut_slice
()
.
sort_by
(|
a
,
b
|
b
.cmp
(
a
));
v1
.sort_by
(|
a
,
b
|
b
.cmp
(
a
));
assert
!
(
v1
.as_slice
()
.windows
(
2
)
.all
(|
w
|
w
[
0
]
>=
w
[
1
]));
}
}
...
...
src/libcollections/vec.rs
浏览文件 @
5a240588
...
...
@@ -211,7 +211,7 @@ pub fn from_fn(length: uint, op: |uint| -> T) -> Vec<T> {
let
mut
xs
=
Vec
::
with_capacity
(
length
);
while
xs
.len
<
length
{
let
len
=
xs
.len
;
ptr
::
write
(
xs
.
as_mut_slice
()
.
unsafe_mut
(
len
),
op
(
len
));
ptr
::
write
(
xs
.unsafe_mut
(
len
),
op
(
len
));
xs
.len
+=
1
;
}
xs
...
...
@@ -328,7 +328,7 @@ pub fn from_elem(length: uint, value: T) -> Vec<T> {
let
mut
xs
=
Vec
::
with_capacity
(
length
);
while
xs
.len
<
length
{
let
len
=
xs
.len
;
ptr
::
write
(
xs
.
as_mut_slice
()
.
unsafe_mut
(
len
),
ptr
::
write
(
xs
.unsafe_mut
(
len
),
value
.clone
());
xs
.len
+=
1
;
}
...
...
@@ -361,7 +361,7 @@ pub fn push_all(&mut self, other: &[T]) {
// during the loop can prevent this optimisation.
unsafe
{
ptr
::
write
(
self
.
as_mut_slice
()
.
unsafe_mut
(
len
),
self
.unsafe_mut
(
len
),
other
.unsafe_get
(
i
)
.clone
());
self
.set_len
(
len
+
1
);
}
...
...
@@ -896,7 +896,7 @@ pub unsafe fn set_len(&mut self, len: uint) {
pub
fn
swap_remove
(
&
mut
self
,
index
:
uint
)
->
Option
<
T
>
{
let
length
=
self
.len
();
if
length
>
0
&&
index
<
length
-
1
{
self
.
as_mut_slice
()
.
swap
(
index
,
length
-
1
);
self
.swap
(
index
,
length
-
1
);
}
else
if
index
>=
length
{
return
None
}
...
...
@@ -1231,7 +1231,7 @@ pub fn dedup(&mut self) {
if
ln
<
1
{
return
;
}
// Avoid bounds checks by using unsafe pointers.
let
p
=
self
.as_mut_
slice
()
.as_mut_
ptr
();
let
p
=
self
.as_mut_ptr
();
let
mut
r
=
1
;
let
mut
w
=
1
;
...
...
@@ -1293,7 +1293,7 @@ fn drop(&mut self) {
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
if
self
.cap
!=
0
{
unsafe
{
for
x
in
self
.
as_mut_slice
()
.
iter
()
{
for
x
in
self
.iter
()
{
ptr
::
read
(
x
);
}
dealloc
(
self
.ptr
,
self
.cap
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录