Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3296bd7e
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
3296bd7e
编写于
5月 03, 2014
作者:
K
Kevin Ballard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename slice::unzip() to vec::unzip()
unzip() has nothing to do with slices, so it belongs in vec.
上级
21dae8e1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
36 deletion
+38
-36
src/librustc/middle/trans/consts.rs
src/librustc/middle/trans/consts.rs
+3
-3
src/libstd/slice.rs
src/libstd/slice.rs
+0
-31
src/libstd/sync/deque.rs
src/libstd/sync/deque.rs
+2
-2
src/libstd/vec.rs
src/libstd/vec.rs
+33
-0
未找到文件。
src/librustc/middle/trans/consts.rs
浏览文件 @
3296bd7e
...
...
@@ -33,7 +33,7 @@
use
util
::
ppaux
::{
Repr
,
ty_to_str
};
use
std
::
c_str
::
ToCStr
;
use
std
::
slice
;
use
std
::
{
slice
,
vec
}
;
use
std
::
vec
::
Vec
;
use
libc
::
c_uint
;
use
syntax
::{
ast
,
ast_util
};
...
...
@@ -94,7 +94,7 @@ fn const_vec(cx: &CrateContext, e: &ast::Expr,
let
vec_ty
=
ty
::
expr_ty
(
cx
.tcx
(),
e
);
let
unit_ty
=
ty
::
sequence_element_type
(
cx
.tcx
(),
vec_ty
);
let
llunitty
=
type_of
::
type_of
(
cx
,
unit_ty
);
let
(
vs
,
inlineable
)
=
slice
::
unzip
(
es
.iter
()
.map
(|
e
|
const_expr
(
cx
,
*
e
,
is_local
)));
let
(
vs
,
inlineable
)
=
vec
::
unzip
(
es
.iter
()
.map
(|
e
|
const_expr
(
cx
,
*
e
,
is_local
)));
// If the vector contains enums, an LLVM array won't work.
let
v
=
if
vs
.iter
()
.any
(|
vi
|
val_ty
(
*
vi
)
!=
llunitty
)
{
C_struct
(
cx
,
vs
,
false
)
...
...
@@ -539,7 +539,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
};
expr
::
with_field_tys
(
tcx
,
ety
,
Some
(
e
.id
),
|
discr
,
field_tys
|
{
let
(
cs
,
inlineable
)
=
slice
::
unzip
(
field_tys
.iter
()
.enumerate
()
let
(
cs
,
inlineable
)
=
vec
::
unzip
(
field_tys
.iter
()
.enumerate
()
.map
(|(
ix
,
&
field_ty
)|
{
match
fs
.iter
()
.find
(|
f
|
field_ty
.ident.name
==
f
.ident.node.name
)
{
Some
(
f
)
=>
const_expr
(
cx
,
(
*
f
)
.expr
,
is_local
),
...
...
src/libstd/slice.rs
浏览文件 @
3296bd7e
...
...
@@ -155,25 +155,6 @@ fn connect_vec(&self, sep: &T) -> Vec<T> {
}
}
/**
* Convert an iterator of pairs into a pair of vectors.
*
* Returns a tuple containing two vectors where the i-th element of the first
* vector contains the first element of the i-th tuple of the input iterator,
* and the i-th element of the second vector contains the second element
* of the i-th tuple of the input iterator.
*/
pub
fn
unzip
<
T
,
U
,
V
:
Iterator
<
(
T
,
U
)
>>
(
mut
iter
:
V
)
->
(
~
[
T
],
~
[
U
])
{
let
(
lo
,
_
)
=
iter
.size_hint
();
let
mut
ts
=
Vec
::
with_capacity
(
lo
);
let
mut
us
=
Vec
::
with_capacity
(
lo
);
for
(
t
,
u
)
in
iter
{
ts
.push
(
t
);
us
.push
(
u
);
}
(
ts
.move_iter
()
.collect
(),
us
.move_iter
()
.collect
())
}
/// An Iterator that yields the element swaps needed to produce
/// a sequence of all possible permutations for an indexed sequence of
/// elements. Each permutation is only a single swap apart.
...
...
@@ -1242,18 +1223,6 @@ fn test_retain() {
assert_eq!
(
v
,
vec!
[
1
,
3
,
5
]);
}
#[test]
fn
test_zip_unzip
()
{
let
z1
=
vec!
[(
1
,
4
),
(
2
,
5
),
(
3
,
6
)];
let
(
left
,
right
)
=
unzip
(
z1
.iter
()
.map
(|
&
x
|
x
));
let
(
left
,
right
)
=
(
left
.as_slice
(),
right
.as_slice
());
assert_eq!
((
1
,
4
),
(
left
[
0
],
right
[
0
]));
assert_eq!
((
2
,
5
),
(
left
[
1
],
right
[
1
]));
assert_eq!
((
3
,
6
),
(
left
[
2
],
right
[
2
]));
}
#[test]
fn
test_element_swaps
()
{
let
mut
v
=
[
1
,
2
,
3
];
...
...
src/libstd/sync/deque.rs
浏览文件 @
3296bd7e
...
...
@@ -407,7 +407,7 @@ mod tests {
use
rand
::
Rng
;
use
sync
::
atomics
::{
AtomicBool
,
INIT_ATOMIC_BOOL
,
SeqCst
,
AtomicUint
,
INIT_ATOMIC_UINT
};
use
slice
;
use
vec
;
#[test]
fn
smoke
()
{
...
...
@@ -603,7 +603,7 @@ fn no_starvation() {
let
mut
pool
=
BufferPool
::
<
(
int
,
uint
)
>
::
new
();
let
(
mut
w
,
s
)
=
pool
.deque
();
let
(
threads
,
hits
)
=
slice
::
unzip
(
range
(
0
,
NTHREADS
)
.map
(|
_
|
{
let
(
threads
,
hits
)
=
vec
::
unzip
(
range
(
0
,
NTHREADS
)
.map
(|
_
|
{
let
s
=
s
.clone
();
let
unique_box
=
box
AtomicUint
::
new
(
0
);
let
thread_box
=
unsafe
{
...
...
src/libstd/vec.rs
浏览文件 @
3296bd7e
...
...
@@ -1436,10 +1436,31 @@ fn drop(&mut self) {
}
}
/**
* Convert an iterator of pairs into a pair of vectors.
*
* Returns a tuple containing two vectors where the i-th element of the first
* vector contains the first element of the i-th tuple of the input iterator,
* and the i-th element of the second vector contains the second element
* of the i-th tuple of the input iterator.
*/
pub
fn
unzip
<
T
,
U
,
V
:
Iterator
<
(
T
,
U
)
>>
(
mut
iter
:
V
)
->
(
Vec
<
T
>
,
Vec
<
U
>
)
{
let
(
lo
,
_
)
=
iter
.size_hint
();
let
mut
ts
=
Vec
::
with_capacity
(
lo
);
let
mut
us
=
Vec
::
with_capacity
(
lo
);
for
(
t
,
u
)
in
iter
{
ts
.push
(
t
);
us
.push
(
u
);
}
(
ts
,
us
)
}
#[cfg(test)]
mod
tests
{
use
prelude
::
*
;
use
mem
::
size_of
;
use
super
::
unzip
;
#[test]
fn
test_small_vec_struct
()
{
...
...
@@ -1687,4 +1708,16 @@ fn test_connect() {
assert_eq!
([
&
[
1
],
&
[
2
,
3
]]
.connect_vec
(
&
0
),
vec!
[
1
,
0
,
2
,
3
]);
assert_eq!
([
&
[
1
],
&
[
2
],
&
[
3
]]
.connect_vec
(
&
0
),
vec!
[
1
,
0
,
2
,
0
,
3
]);
}
#[test]
fn
test_zip_unzip
()
{
let
z1
=
vec!
[(
1
,
4
),
(
2
,
5
),
(
3
,
6
)];
let
(
left
,
right
)
=
unzip
(
z1
.iter
()
.map
(|
&
x
|
x
));
let
(
left
,
right
)
=
(
left
.as_slice
(),
right
.as_slice
());
assert_eq!
((
1
,
4
),
(
left
[
0
],
right
[
0
]));
assert_eq!
((
2
,
5
),
(
left
[
1
],
right
[
1
]));
assert_eq!
((
3
,
6
),
(
left
[
2
],
right
[
2
]));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录