Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c9e6bda9
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,发现更多精彩内容 >>
提交
c9e6bda9
编写于
11月 14, 2014
作者:
B
Brendan Zabarauskas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert the need for initial values with arithmetic iterators
上级
064e84e3
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
71 addition
and
40 deletion
+71
-40
src/libcollections/slice.rs
src/libcollections/slice.rs
+1
-1
src/libcollections/str.rs
src/libcollections/str.rs
+3
-3
src/libcore/iter.rs
src/libcore/iter.rs
+50
-18
src/libcoretest/iter.rs
src/libcoretest/iter.rs
+6
-6
src/librustc/middle/check_match.rs
src/librustc/middle/check_match.rs
+1
-1
src/librustc/middle/trans/_match.rs
src/librustc/middle/trans/_match.rs
+1
-1
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/astconv.rs
+1
-1
src/librustdoc/stability_summary.rs
src/librustdoc/stability_summary.rs
+3
-4
src/libstd/path/posix.rs
src/libstd/path/posix.rs
+1
-1
src/libstd/path/windows.rs
src/libstd/path/windows.rs
+1
-1
src/libunicode/u_str.rs
src/libunicode/u_str.rs
+1
-1
src/test/bench/shootout-spectralnorm.rs
src/test/bench/shootout-spectralnorm.rs
+1
-1
src/test/run-pass/issue-15673.rs
src/test/run-pass/issue-15673.rs
+1
-1
未找到文件。
src/libcollections/slice.rs
浏览文件 @
c9e6bda9
...
...
@@ -228,7 +228,7 @@ fn new_pos(i: uint, s: Direction) -> uint {
#[inline]
fn
size_hint
(
&
self
)
->
(
uint
,
Option
<
uint
>
)
{
// For a vector of size n, there are exactly n! permutations.
let
n
=
range
(
2
,
self
.sdir
.len
()
+
1
)
.product
(
1
);
let
n
=
range
(
2
,
self
.sdir
.len
()
+
1
)
.product
();
(
n
-
self
.swaps_made
,
Some
(
n
-
self
.swaps_made
))
}
}
...
...
src/libcollections/str.rs
浏览文件 @
c9e6bda9
...
...
@@ -116,7 +116,7 @@ fn concat(&self) -> String {
}
// `len` calculation may overflow but push_str will check boundaries
let
len
=
self
.iter
()
.map
(|
s
|
s
.as_slice
()
.len
())
.sum
(
0
);
let
len
=
self
.iter
()
.map
(|
s
|
s
.as_slice
()
.len
())
.sum
();
let
mut
result
=
String
::
with_capacity
(
len
);
...
...
@@ -140,7 +140,7 @@ fn connect(&self, sep: &str) -> String {
// this is wrong without the guarantee that `self` is non-empty
// `len` calculation may overflow but push_str but will check boundaries
let
len
=
sep
.len
()
*
(
self
.len
()
-
1
)
+
self
.iter
()
.map
(|
s
|
s
.as_slice
()
.len
())
.sum
(
0
);
+
self
.iter
()
.map
(|
s
|
s
.as_slice
()
.len
())
.sum
();
let
mut
result
=
String
::
with_capacity
(
len
);
let
mut
first
=
true
;
...
...
@@ -2151,7 +2151,7 @@ fn t<S: Default + Str>() {
#[test]
fn
test_str_container
()
{
fn
sum_len
(
v
:
&
[
&
str
])
->
uint
{
v
.iter
()
.map
(|
x
|
x
.len
())
.sum
(
0
)
v
.iter
()
.map
(|
x
|
x
.len
())
.sum
()
}
let
s
=
String
::
from_str
(
"01234"
);
...
...
src/libcore/iter.rs
浏览文件 @
c9e6bda9
...
...
@@ -63,7 +63,7 @@ trait defined in this module. For loops can be viewed as a syntactical expansion
use
cmp
::
Ord
;
use
mem
;
use
num
::{
ToPrimitive
,
Int
};
use
ops
::
{
Add
,
Mul
}
;
use
ops
::
Add
;
use
option
::{
Option
,
Some
,
None
};
use
uint
;
#[deprecated
=
"renamed to Extend"
]
pub
use
self
::
Extend
as
Extendable
;
...
...
@@ -402,7 +402,7 @@ fn fuse(self) -> Fuse<Self> {
/// .inspect(|&x| println!("filtering {}", x))
/// .filter(|&x| x % 2 == 0)
/// .inspect(|&x| println!("{} made it through", x))
/// .sum(
0
);
/// .sum();
/// println!("{}", sum);
/// ```
#[inline]
...
...
@@ -784,17 +784,33 @@ pub trait AdditiveIterator<A> {
///
/// let a = [1i, 2, 3, 4, 5];
/// let mut it = a.iter().map(|&x| x);
/// assert!(it.sum(
0
) == 15);
/// assert!(it.sum() == 15);
/// ```
fn
sum
(
&
mut
self
,
init
:
A
)
->
A
;
fn
sum
(
&
mut
self
)
->
A
;
}
impl
<
A
:
Add
<
A
,
A
>
,
T
:
Iterator
<
A
>>
AdditiveIterator
<
A
>
for
T
{
macro_rules!
impl_additive
{
(
$A:ty
,
$init:expr
)
=>
{
impl
<
T
:
Iterator
<
$A
>>
AdditiveIterator
<
$A
>
for
T
{
#[inline]
fn
sum
(
&
mut
self
,
init
:
A
)
->
A
{
self
.fold
(
init
,
|
s
,
x
|
s
+
x
)
fn
sum
(
&
mut
self
)
->
$
A
{
self
.fold
(
$init
,
|
acc
,
x
|
acc
+
x
)
}
}
};
}
impl_additive!
(
i8
,
0
)
impl_additive!
(
i16
,
0
)
impl_additive!
(
i32
,
0
)
impl_additive!
(
i64
,
0
)
impl_additive!
(
int
,
0
)
impl_additive!
(
u8
,
0
)
impl_additive!
(
u16
,
0
)
impl_additive!
(
u32
,
0
)
impl_additive!
(
u64
,
0
)
impl_additive!
(
uint
,
0
)
impl_additive!
(
f32
,
0.0
)
impl_additive!
(
f64
,
0.0
)
/// A trait for iterators over elements which can be multiplied together.
pub
trait
MultiplicativeIterator
<
A
>
{
...
...
@@ -806,21 +822,37 @@ pub trait MultiplicativeIterator<A> {
/// use std::iter::{count, MultiplicativeIterator};
///
/// fn factorial(n: uint) -> uint {
/// count(1u, 1).take_while(|&i| i <= n).product(
1
)
/// count(1u, 1).take_while(|&i| i <= n).product()
/// }
/// assert!(factorial(0) == 1);
/// assert!(factorial(1) == 1);
/// assert!(factorial(5) == 120);
/// ```
fn
product
(
&
mut
self
,
init
:
A
)
->
A
;
fn
product
(
&
mut
self
)
->
A
;
}
impl
<
A
:
Mul
<
A
,
A
>
,
T
:
Iterator
<
A
>>
MultiplicativeIterator
<
A
>
for
T
{
macro_rules!
impl_multiplicative
{
(
$A:ty
,
$init:expr
)
=>
{
impl
<
T
:
Iterator
<
$A
>>
MultiplicativeIterator
<
$A
>
for
T
{
#[inline]
fn
product
(
&
mut
self
,
init
:
A
)
->
A
{
self
.fold
(
init
,
|
p
,
x
|
p
*
x
)
fn
product
(
&
mut
self
)
->
$
A
{
self
.fold
(
$init
,
|
acc
,
x
|
acc
*
x
)
}
}
};
}
impl_multiplicative!
(
i8
,
1
)
impl_multiplicative!
(
i16
,
1
)
impl_multiplicative!
(
i32
,
1
)
impl_multiplicative!
(
i64
,
1
)
impl_multiplicative!
(
int
,
1
)
impl_multiplicative!
(
u8
,
1
)
impl_multiplicative!
(
u16
,
1
)
impl_multiplicative!
(
u32
,
1
)
impl_multiplicative!
(
u64
,
1
)
impl_multiplicative!
(
uint
,
1
)
impl_multiplicative!
(
f32
,
1.0
)
impl_multiplicative!
(
f64
,
1.0
)
/// A trait for iterators over elements which can be compared to one another.
pub
trait
OrdIterator
<
A
>
{
...
...
src/libcoretest/iter.rs
浏览文件 @
c9e6bda9
...
...
@@ -294,17 +294,17 @@ fn test_iterator_len() {
#[test]
fn
test_iterator_sum
()
{
let
v
:
&
[
_
]
=
&
[
0
i
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
];
assert_eq!
(
v
[
0
..
4
]
.iter
()
.map
(|
&
x
|
x
)
.sum
(
0
),
6
);
assert_eq!
(
v
.iter
()
.map
(|
&
x
|
x
)
.sum
(
0
),
55
);
assert_eq!
(
v
[
0
..
0
]
.iter
()
.map
(|
&
x
|
x
)
.sum
(
0
),
0
);
assert_eq!
(
v
[
0
..
4
]
.iter
()
.map
(|
&
x
|
x
)
.sum
(),
6
);
assert_eq!
(
v
.iter
()
.map
(|
&
x
|
x
)
.sum
(),
55
);
assert_eq!
(
v
[
0
..
0
]
.iter
()
.map
(|
&
x
|
x
)
.sum
(),
0
);
}
#[test]
fn
test_iterator_product
()
{
let
v
:
&
[
_
]
=
&
[
0
i
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
];
assert_eq!
(
v
[
0
..
4
]
.iter
()
.map
(|
&
x
|
x
)
.product
(
1
),
0
);
assert_eq!
(
v
[
1
..
5
]
.iter
()
.map
(|
&
x
|
x
)
.product
(
1
),
24
);
assert_eq!
(
v
[
0
..
0
]
.iter
()
.map
(|
&
x
|
x
)
.product
(
1
),
1
);
assert_eq!
(
v
[
0
..
4
]
.iter
()
.map
(|
&
x
|
x
)
.product
(),
0
);
assert_eq!
(
v
[
1
..
5
]
.iter
()
.map
(|
&
x
|
x
)
.product
(),
24
);
assert_eq!
(
v
[
0
..
0
]
.iter
()
.map
(|
&
x
|
x
)
.product
(),
1
);
}
#[test]
...
...
src/librustc/middle/check_match.rs
浏览文件 @
c9e6bda9
...
...
@@ -70,7 +70,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
pretty_printed_matrix
.iter
()
.map
(|
row
|
row
[
col
]
.len
())
.max
()
.unwrap_or
(
0u
)
})
.collect
();
let
total_width
=
column_widths
.iter
()
.map
(|
n
|
*
n
)
.sum
(
0
)
+
column_count
*
3
+
1
;
let
total_width
=
column_widths
.iter
()
.map
(|
n
|
*
n
)
.sum
()
+
column_count
*
3
+
1
;
let
br
=
String
::
from_char
(
total_width
,
'+'
);
try!
(
write!
(
f
,
"{}
\n
"
,
br
));
for
row
in
pretty_printed_matrix
.into_iter
()
{
...
...
src/librustc/middle/trans/_match.rs
浏览文件 @
c9e6bda9
...
...
@@ -756,7 +756,7 @@ fn pat_score(def_map: &DefMap, pat: &ast::Pat) -> uint {
let
total_score
=
m
.iter
()
.map
(|
row
|
row
.pats
[
col
])
.map
(|
pat
|
pat_score
(
def_map
,
pat
))
.sum
(
0
);
.sum
();
// Irrefutable columns always go first, they'd only be duplicated in the branches.
if
total_score
==
0
{
...
...
src/librustc/middle/typeck/astconv.rs
浏览文件 @
c9e6bda9
...
...
@@ -1194,7 +1194,7 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>(
lifetimes_for_params
.push
((
input_pat
,
accumulator
));
}
if
lifetimes_for_params
.iter
()
.map
(|
&
(
_
,
ref
x
)|
x
.len
())
.sum
(
0
)
==
1
{
if
lifetimes_for_params
.iter
()
.map
(|
&
(
_
,
ref
x
)|
x
.len
())
.sum
()
==
1
{
implied_output_region
=
Some
(
lifetimes_for_params
.iter
()
.filter_map
(|
&
(
_
,
ref
x
)|
...
...
src/librustdoc/stability_summary.rs
浏览文件 @
c9e6bda9
...
...
@@ -15,7 +15,6 @@
use
std
::
ops
::
Add
;
use
std
::
num
::
Zero
;
use
std
::
iter
::
AdditiveIterator
;
use
syntax
::
attr
::{
Deprecated
,
Experimental
,
Unstable
,
Stable
,
Frozen
,
Locked
};
use
syntax
::
ast
::
Public
;
...
...
@@ -152,14 +151,14 @@ fn summarize_item(item: &Item) -> (Counts, Option<ModuleSummary>) {
let
subcounts
=
subitems
.iter
()
.filter
(|
i
|
visible
(
*
i
))
.map
(
summarize_item
)
.map
(|
s
|
s
.val0
())
.
sum
(
Counts
::
zero
()
);
.
fold
(
Counts
::
zero
(),
|
acc
,
x
|
acc
+
x
);
(
item_counts
+
subcounts
,
None
)
}
// `pub` automatically
EnumItem
(
Enum
{
variants
:
ref
subitems
,
..
})
=>
{
let
subcounts
=
subitems
.iter
()
.map
(
summarize_item
)
.map
(|
s
|
s
.val0
())
.
sum
(
Counts
::
zero
()
);
.
fold
(
Counts
::
zero
(),
|
acc
,
x
|
acc
+
x
);
(
item_counts
+
subcounts
,
None
)
}
TraitItem
(
Trait
{
...
...
@@ -177,7 +176,7 @@ fn extract_item<'a>(trait_item: &'a TraitMethod) -> &'a Item {
.map
(
extract_item
)
.map
(
summarize_item
)
.map
(|
s
|
s
.val0
())
.
sum
(
Counts
::
zero
()
);
.
fold
(
Counts
::
zero
(),
|
acc
,
x
|
acc
+
x
);
(
item_counts
+
subcounts
,
None
)
}
ModuleItem
(
Module
{
ref
items
,
..
})
=>
{
...
...
src/libstd/path/posix.rs
浏览文件 @
c9e6bda9
...
...
@@ -356,7 +356,7 @@ fn normalize<V: AsSlice<u8>>(v: V) -> Vec<u8> {
Some
(
vec!
[
SEP_BYTE
])
}
else
{
let
n
=
if
is_abs
{
comps
.len
()
}
else
{
comps
.len
()
-
1
}
+
comps
.iter
()
.map
(|
v
|
v
.len
())
.sum
(
0
);
comps
.iter
()
.map
(|
v
|
v
.len
())
.sum
();
let
mut
v
=
Vec
::
with_capacity
(
n
);
let
mut
it
=
comps
.into_iter
();
if
!
is_abs
{
...
...
src/libstd/path/windows.rs
浏览文件 @
c9e6bda9
...
...
@@ -781,7 +781,7 @@ fn normalize__(s: &str, prefix: Option<PathPrefix>) -> Option<String> {
let
prefix_
=
s
.slice_to
(
prefix_len
(
prefix
));
let
n
=
prefix_
.len
()
+
if
is_abs
{
comps
.len
()
}
else
{
comps
.len
()
-
1
}
+
comps
.iter
()
.map
(|
v
|
v
.len
())
.sum
(
0
);
comps
.iter
()
.map
(|
v
|
v
.len
())
.sum
();
let
mut
s
=
String
::
with_capacity
(
n
);
match
prefix
{
Some
(
DiskPrefix
)
=>
{
...
...
src/libunicode/u_str.rs
浏览文件 @
c9e6bda9
...
...
@@ -153,7 +153,7 @@ fn is_alphanumeric(&self) -> bool { self.chars().all(u_char::is_alphanumeric) }
#[inline]
fn
width
(
&
self
,
is_cjk
:
bool
)
->
uint
{
self
.chars
()
.map
(|
c
|
c
.width
(
is_cjk
)
.unwrap_or
(
0
))
.sum
(
0
)
self
.chars
()
.map
(|
c
|
c
.width
(
is_cjk
)
.unwrap_or
(
0
))
.sum
()
}
#[inline]
...
...
src/test/bench/shootout-spectralnorm.rs
浏览文件 @
c9e6bda9
...
...
@@ -105,7 +105,7 @@ fn A(i: uint, j: uint) -> f64 {
}
fn
dot
(
v
:
&
[
f64
],
u
:
&
[
f64
])
->
f64
{
v
.iter
()
.zip
(
u
.iter
())
.map
(|(
a
,
b
)|
*
a
*
*
b
)
.sum
(
0.0
)
v
.iter
()
.zip
(
u
.iter
())
.map
(|(
a
,
b
)|
*
a
*
*
b
)
.sum
()
}
// Executes a closure in parallel over the given mutable slice. The closure `f`
...
...
src/test/run-pass/issue-15673.rs
浏览文件 @
c9e6bda9
...
...
@@ -11,5 +11,5 @@
use
std
::
iter
::
AdditiveIterator
;
fn
main
()
{
let
x
:
[
u64
,
..
3
]
=
[
1
,
2
,
3
];
assert_eq!
(
6
,
range
(
0
,
3
)
.map
(|
i
|
x
[
i
])
.sum
(
0
));
assert_eq!
(
6
,
range
(
0
,
3
)
.map
(|
i
|
x
[
i
])
.sum
());
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录