Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c3b98cab
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,发现更多精彩内容 >>
提交
c3b98cab
编写于
6月 27, 2012
作者:
E
Eric Holk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed pretty much all the vector+ from core (issue #2719)
上级
e2205659
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
84 addition
and
54 deletion
+84
-54
src/libcore/dvec.rs
src/libcore/dvec.rs
+2
-1
src/libcore/either.rs
src/libcore/either.rs
+6
-3
src/libcore/extfmt.rs
src/libcore/extfmt.rs
+3
-3
src/libcore/iter.rs
src/libcore/iter.rs
+1
-1
src/libcore/rand.rs
src/libcore/rand.rs
+1
-1
src/libcore/result.rs
src/libcore/result.rs
+2
-2
src/libcore/run.rs
src/libcore/run.rs
+5
-5
src/libcore/str.rs
src/libcore/str.rs
+16
-15
src/libcore/vec.rs
src/libcore/vec.rs
+48
-23
未找到文件。
src/libcore/dvec.rs
浏览文件 @
c3b98cab
...
...
@@ -150,7 +150,8 @@ fn unshift(-t: A) {
let
data_ptr
:
*
()
=
unsafe
::
reinterpret_cast
(
data
);
if
data_ptr
.is_null
()
{
fail
"Recursive use of dvec"
;
}
log
(
error
,
"a"
);
self
.data
<-
[
mut
t
]
/~
+
data
;
self
.data
<-
[
mut
t
]
/~
;
vec
::
push_all_move
(
self
.data
,
data
);
log
(
error
,
"b"
);
}
}
...
...
src/libcore/either.rs
浏览文件 @
c3b98cab
...
...
@@ -26,7 +26,7 @@ fn lefts<T: copy, U>(eithers: [either<T, U>]/~) -> [T]/~ {
let
mut
result
:
[
T
]
/~
=
[]
/~
;
for
vec
::
each
(
eithers
)
{|
elt
|
alt
elt
{
left
(
l
)
{
result
+=
[
l
]
/~
;
}
_
{
/* fallthrough */
}
}
alt
elt
{
left
(
l
)
{
vec
::
push
(
result
,
l
)
;
}
_
{
/* fallthrough */
}
}
}
ret
result
;
}
...
...
@@ -36,7 +36,7 @@ fn rights<T, U: copy>(eithers: [either<T, U>]/~) -> [U]/~ {
let
mut
result
:
[
U
]
/~
=
[]
/~
;
for
vec
::
each
(
eithers
)
{|
elt
|
alt
elt
{
right
(
r
)
{
result
+=
[
r
]
/~
;
}
_
{
/* fallthrough */
}
}
alt
elt
{
right
(
r
)
{
vec
::
push
(
result
,
r
)
;
}
_
{
/* fallthrough */
}
}
}
ret
result
;
}
...
...
@@ -53,7 +53,10 @@ fn partition<T: copy, U: copy>(eithers: [either<T, U>]/~)
let
mut
lefts
:
[
T
]
/~
=
[]
/~
;
let
mut
rights
:
[
U
]
/~
=
[]
/~
;
for
vec
::
each
(
eithers
)
{|
elt
|
alt
elt
{
left
(
l
)
{
lefts
+=
[
l
]
/~
;
}
right
(
r
)
{
rights
+=
[
r
]
/~
;
}
}
alt
elt
{
left
(
l
)
{
vec
::
push
(
lefts
,
l
);
}
right
(
r
)
{
vec
::
push
(
rights
,
r
);
}
}
}
ret
{
lefts
:
lefts
,
rights
:
rights
};
}
...
...
src/libcore/extfmt.rs
浏览文件 @
c3b98cab
...
...
@@ -88,7 +88,7 @@ fn parse_fmt_string(s: str, error: error_fn) -> [piece]/~ {
fn
flush_buf
(
buf
:
str
,
&
pieces
:
[
piece
]
/~
)
->
str
{
if
str
::
len
(
buf
)
>
0u
{
let
piece
=
piece_string
(
buf
);
pieces
+=
[
piece
]
/~
;
vec
::
push
(
pieces
,
piece
)
;
}
ret
""
;
}
...
...
@@ -108,7 +108,7 @@ fn flush_buf(buf: str, &pieces: [piece]/~) -> str {
}
else
{
buf
=
flush_buf
(
buf
,
pieces
);
let
rs
=
parse_conversion
(
s
,
i
,
lim
,
error
);
pieces
+=
[
rs
.piece
]
/~
;
vec
::
push
(
pieces
,
rs
.piece
)
;
i
=
rs
.next
;
}
}
else
{
buf
+=
curr
;
i
+=
size
;
}
...
...
@@ -172,7 +172,7 @@ fn more_(f: flag, s: str, i: uint, lim: uint) ->
let
rest
=
next
.flags
;
let
j
=
next
.next
;
let
curr
:
[
flag
]
/~
=
[
f
]
/~
;
ret
{
flags
:
curr
+
rest
,
next
:
j
};
ret
{
flags
:
vec
::
append
(
curr
,
rest
)
,
next
:
j
};
}
let
more
=
{|
x
|
more_
(
x
,
s
,
i
,
lim
)};
let
f
=
s
[
i
];
...
...
src/libcore/iter.rs
浏览文件 @
c3b98cab
...
...
@@ -65,7 +65,7 @@ fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
}
fn
to_vec
<
A
:
copy
,
IA
:
base_iter
<
A
>>
(
self
:
IA
)
->
[
A
]
/~
{
foldl
::
<
A
,[
A
]
/~
,
IA
>
(
self
,
[]
/~
,
{|
r
,
a
|
r
+
[
a
]
/~
})
foldl
::
<
A
,[
A
]
/~
,
IA
>
(
self
,
[]
/~
,
{|
r
,
a
|
vec
::
append
(
r
,
[
a
]
/~
)
})
}
fn
contains
<
A
,
IA
:
base_iter
<
A
>>
(
self
:
IA
,
x
:
A
)
->
bool
{
...
...
src/libcore/rand.rs
浏览文件 @
c3b98cab
...
...
@@ -204,7 +204,7 @@ fn weighted_vec<T:copy>(v: [weighted<T>]/~) -> [T]/~ {
let
mut
r
=
[]
/~
;
for
v
.each
{|
item
|
for
uint
::
range
(
0u
,
item
.weight
)
{|
_
i
|
r
+=
[
item
.item
]
/~
;
vec
::
push
(
r
,
item
.item
)
;
}
}
r
...
...
src/libcore/result.rs
浏览文件 @
c3b98cab
...
...
@@ -256,7 +256,7 @@ fn map_vec<T,U:copy,V:copy>(
vec
::
reserve
(
vs
,
vec
::
len
(
ts
));
for
vec
::
each
(
ts
)
{|
t
|
alt
op
(
t
)
{
ok
(
v
)
{
v
s
+=
[
v
]
/~
;
}
ok
(
v
)
{
v
ec
::
push
(
vs
,
v
)
;
}
err
(
u
)
{
ret
err
(
u
);
}
}
}
...
...
@@ -294,7 +294,7 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: [S]/~, ts: [T]/~,
let
mut
i
=
0u
;
while
i
<
n
{
alt
op
(
ss
[
i
],
ts
[
i
])
{
ok
(
v
)
{
v
s
+=
[
v
]
/~
;
}
ok
(
v
)
{
v
ec
::
push
(
vs
,
v
)
;
}
err
(
u
)
{
ret
err
(
u
);
}
}
i
+=
1u
;
...
...
src/libcore/run.rs
浏览文件 @
c3b98cab
...
...
@@ -83,10 +83,10 @@ fn with_argv<T>(prog: str, args: [str]/~,
let
mut
tmps
=
[]
/~
;
for
vec
::
each
(
args
)
{|
arg
|
let
t
=
@
arg
;
tmps
+=
[
t
]
/~
;
argptrs
+=
str
::
as_c_str
(
*
t
)
{|
b
|
[
b
]
/~
}
;
vec
::
push
(
tmps
,
t
)
;
vec
::
push_all
(
argptrs
,
str
::
as_c_str
(
*
t
)
{|
b
|
[
b
]
/~
})
;
}
argptrs
+=
[
ptr
::
null
()]
/~
;
vec
::
push
(
argptrs
,
ptr
::
null
())
;
vec
::
as_buf
(
argptrs
,
cb
)
}
...
...
@@ -104,9 +104,9 @@ fn with_envp<T>(env: option<[(str,str)]/~>,
let
(
k
,
v
)
=
e
;
let
t
=
@
(
#
fmt
(
"%s=%s"
,
k
,
v
));
vec
::
push
(
tmps
,
t
);
ptrs
+=
str
::
as_c_str
(
*
t
)
{|
b
|
[
b
]
/~
}
;
vec
::
push_all
(
ptrs
,
str
::
as_c_str
(
*
t
)
{|
b
|
[
b
]
/~
})
;
}
ptrs
+=
[
ptr
::
null
()]
/~
;
vec
::
push
(
ptrs
,
ptr
::
null
())
;
vec
::
as_buf
(
ptrs
)
{
|
p
|
unsafe
{
cb
(::
unsafe
::
reinterpret_cast
(
p
))
}
}
...
...
src/libcore/str.rs
浏览文件 @
c3b98cab
...
...
@@ -347,7 +347,7 @@ fn shift_char(&s: str) -> char {
let
len
=
len
(
s
);
while
i
<
len
{
let
{
ch
,
next
}
=
char_range_at
(
s
,
i
);
buf
+=
[
ch
]
/~
;
unchecked
{
vec
::
push
(
buf
,
ch
);
}
i
=
next
;
}
ret
buf
;
...
...
@@ -407,8 +407,9 @@ fn shift_char(&s: str) -> char {
let
mut
i
=
0u
,
start
=
0u
;
while
i
<
l
&&
done
<
count
{
if
s
[
i
]
==
b
{
if
allow_empty
||
start
<
i
{
result
+=
[
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
i
)
}]
/~
;
if
allow_empty
||
start
<
i
unchecked
{
vec
::
push
(
result
,
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
i
)
});
}
start
=
i
+
1u
;
done
+=
1u
;
...
...
@@ -416,7 +417,7 @@ fn shift_char(&s: str) -> char {
i
+=
1u
;
}
if
allow_empty
||
start
<
l
{
result
+=
[
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
l
)
}]
/~
;
unsafe
{
vec
::
push
(
result
,
unsafe
::
slice_bytes
(
s
,
start
,
l
)
)
}
;
}
result
}
else
{
...
...
@@ -450,16 +451,16 @@ fn shift_char(&s: str) -> char {
while
i
<
l
&&
done
<
count
{
let
{
ch
,
next
}
=
char_range_at
(
s
,
i
);
if
sepfn
(
ch
)
{
if
allow_empty
||
start
<
i
{
result
+=
[
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
i
)
}]
/~
;
if
allow_empty
||
start
<
i
unchecked
{
vec
::
push
(
result
,
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
i
)})
;
}
start
=
next
;
done
+=
1u
;
}
i
=
next
;
}
if
allow_empty
||
start
<
l
{
result
+=
[
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
l
)
}]
/~
;
if
allow_empty
||
start
<
l
unchecked
{
vec
::
push
(
result
,
unsafe
{
unsafe
::
slice_bytes
(
s
,
start
,
l
)
})
;
}
result
}
...
...
@@ -513,7 +514,7 @@ fn shift_char(&s: str) -> char {
pure
fn
split_str
(
s
:
str
/&
a
,
sep
:
str
/&
b
)
->
[
str
]
/~
{
let
mut
result
=
[]
/~
;
iter_between_matches
(
s
,
sep
)
{|
from
,
to
|
unsafe
{
result
+=
[
unsafe
::
slice_bytes
(
s
,
from
,
to
)]
/~
;
}
unsafe
{
vec
::
push
(
result
,
unsafe
::
slice_bytes
(
s
,
from
,
to
))
;
}
}
result
}
...
...
@@ -522,7 +523,7 @@ fn shift_char(&s: str) -> char {
let
mut
result
=
[]
/~
;
iter_between_matches
(
s
,
sep
)
{|
from
,
to
|
if
to
>
from
{
unsafe
{
result
+=
[
unsafe
::
slice_bytes
(
s
,
from
,
to
)]
/~
;
}
unsafe
{
vec
::
push
(
result
,
unsafe
::
slice_bytes
(
s
,
from
,
to
))
;
}
}
}
result
...
...
@@ -1270,17 +1271,17 @@ fn is_alphanumeric(s: str/&) -> bool {
// Arithmetic with u32 literals is easier on the eyes than chars.
let
mut
ch
=
cch
as
u32
;
if
(
ch
&
0xFFFF_u32
)
==
ch
{
if
(
ch
&
0xFFFF_u32
)
==
ch
unchecked
{
// The BMP falls through (assuming non-surrogate, as it should)
assert
ch
<=
0xD7FF_u32
||
ch
>=
0xE000_u32
;
u
+=
[
ch
as
u16
]
/~
}
else
{
vec
::
push
(
u
,
ch
as
u16
)
}
else
unchecked
{
// Supplementary planes break into surrogates.
assert
ch
>=
0x1_0000_u32
&&
ch
<=
0x10_FFFF_u32
;
ch
-=
0x1_0000_u32
;
let
w1
=
0xD800_u16
|
((
ch
>>
10
)
as
u16
);
let
w2
=
0xDC00_u16
|
((
ch
as
u16
)
&
0x3FF_u16
);
u
+=
[
w1
,
w2
]
/~
vec
::
push_all
(
u
,
[
w1
,
w2
]
/~
)
}
}
ret
u
;
...
...
@@ -1788,7 +1789,7 @@ unsafe fn slice_bytes(s: str/&, begin: uint, end: uint) -> str {
ptr
::
memcpy
(
vbuf
,
src
,
end
-
begin
);
}
vec
::
unsafe
::
set_len
(
v
,
end
-
begin
);
v
+=
[
0u8
]
/~
;
v
ec
::
push
(
v
,
0u8
)
;
::
unsafe
::
transmute
(
v
)
}
}
...
...
src/libcore/vec.rs
浏览文件 @
c3b98cab
...
...
@@ -31,7 +31,7 @@
export
rsplitn
;
export
shift
;
export
pop
;
export
push
,
push_all
;
export
push
,
push_all
,
push_all_move
;
export
grow
;
export
grow_fn
;
export
grow_set
;
...
...
@@ -468,6 +468,20 @@ fn push_all<T: copy>(&v: [const T]/~, rhs: [const T]/&) {
}
}
#[inline(always)]
fn
push_all_move
<
T
>
(
&
v
:
[
const
T
]
/~
,
-
rhs
:
[
const
T
]
/~
)
{
reserve
(
v
,
v
.len
()
+
rhs
.len
());
unsafe
{
unpack_slice
(
rhs
)
{|
p
,
len
|
for
uint
::
range
(
0
,
len
)
{|
i
|
let
x
<-
*
ptr
::
offset
(
p
,
i
);
push
(
v
,
x
);
}
}
unsafe
::
set_len
(
rhs
,
0
);
}
}
// Appending
#[inline(always)]
pure
fn
append
<
T
:
copy
>
(
lhs
:
[
T
]
/&
,
rhs
:
[
const
T
]
/&
)
->
[
T
]
/~
{
...
...
@@ -577,7 +591,7 @@ fn grow_set<T: copy>(&v: [mut T]/~, index: uint, initval: T, val: T) {
"
]
pure
fn
flat_map
<
T
,
U
>
(
v
:
[
T
]
/&
,
f
:
fn
(
T
)
->
[
U
]
/~
)
->
[
U
]
/~
{
let
mut
result
=
[]
/~
;
for
each
(
v
)
{|
elem
|
result
+=
f
(
elem
);
}
for
each
(
v
)
{|
elem
|
unchecked
{
push_all_move
(
result
,
f
(
elem
));
}
}
ret
result
;
}
...
...
@@ -649,7 +663,7 @@ fn grow_set<T: copy>(&v: [mut T]/~, index: uint, initval: T, val: T) {
let
mut
first
=
true
;
for
each
(
v
)
{|
inner
|
if
first
{
first
=
false
;
}
else
{
unsafe
{
push
(
r
,
sep
);
}
}
r
+=
inner
;
unchecked
{
push_all
(
r
,
inner
)
}
;
}
ret
r
;
}
...
...
@@ -873,7 +887,13 @@ fn grow_set<T: copy>(&v: [mut T]/~, index: uint, initval: T, val: T) {
"
]
pure
fn
unzip
<
T
:
copy
,
U
:
copy
>
(
v
:
[(
T
,
U
)]
/&
)
->
([
T
]
/~
,
[
U
]
/~
)
{
let
mut
as
=
[]
/~
,
bs
=
[]
/~
;
for
each
(
v
)
{|
p
|
let
(
a
,
b
)
=
p
;
as
+=
[
a
]
/~
;
bs
+=
[
b
]
/~
;
}
for
each
(
v
)
{|
p
|
let
(
a
,
b
)
=
p
;
unchecked
{
vec
::
push
(
as
,
a
);
vec
::
push
(
bs
,
b
);
}
}
ret
(
as
,
bs
);
}
...
...
@@ -888,7 +908,7 @@ fn grow_set<T: copy>(&v: [mut T]/~, index: uint, initval: T, val: T) {
let
sz
=
len
(
v
);
let
mut
i
=
0u
;
assert
sz
==
len
(
u
);
while
i
<
sz
{
zipped
+=
[(
v
[
i
],
u
[
i
])]
/~
;
i
+=
1u
;
}
while
i
<
sz
unchecked
{
vec
::
push
(
zipped
,
(
v
[
i
],
u
[
i
]))
;
i
+=
1u
;
}
ret
zipped
;
}
...
...
@@ -914,12 +934,14 @@ fn reverse<T>(v: [mut T]/~) {
#[doc
=
"Returns a vector with the order of elements reversed"
]
fn
reversed
<
T
:
copy
>
(
v
:
[
const
T
]
/&
)
->
[
T
]
/~
{
pure
fn
reversed
<
T
:
copy
>
(
v
:
[
const
T
]
/&
)
->
[
T
]
/~
{
let
mut
rs
:
[
T
]
/~
=
[]
/~
;
let
mut
i
=
len
::
<
T
>
(
v
);
if
i
==
0u
{
ret
rs
;
}
else
{
i
-=
1u
;
}
while
i
!=
0u
{
rs
+=
[
v
[
i
]]
/~
;
i
-=
1u
;
}
rs
+=
[
v
[
0
]]
/~
;
unchecked
{
while
i
!=
0u
{
vec
::
push
(
rs
,
v
[
i
]);
i
-=
1u
;
}
vec
::
push
(
rs
,
v
[
0
]);
}
ret
rs
;
}
...
...
@@ -1063,18 +1085,21 @@ fn iter2<U, T>(v1: [U]/&, v2: [T]/&, f: fn(U, T)) {
repeated elements, then some permutations are repeated.
"
]
pure
fn
permute
<
T
:
copy
>
(
v
:
[
T
]
/&
,
put
:
fn
([
T
]
/~
))
{
let
ln
=
len
(
v
);
if
ln
==
0u
{
put
([]
/~
);
}
else
{
let
mut
i
=
0u
;
while
i
<
ln
{
let
elt
=
v
[
i
];
let
rest
=
slice
(
v
,
0u
,
i
)
+
slice
(
v
,
i
+
1u
,
ln
);
permute
(
rest
)
{|
permutation
|
put
([
elt
]
/~
+
permutation
)}
i
+=
1u
;
let
ln
=
len
(
v
);
if
ln
==
0u
{
put
([]
/~
);
}
else
{
let
mut
i
=
0u
;
while
i
<
ln
{
let
elt
=
v
[
i
];
let
mut
rest
=
slice
(
v
,
0u
,
i
);
unchecked
{
push_all
(
rest
,
view
(
v
,
i
+
1u
,
ln
));
}
permute
(
rest
)
{|
permutation
|
put
([
elt
]
/~
+
permutation
)}
i
+=
1u
;
}
}
}
}
pure
fn
windowed
<
TT
:
copy
>
(
nn
:
uint
,
xx
:
[
TT
]
/&
)
->
[[
TT
]
/~
]
/~
{
...
...
@@ -1082,8 +1107,8 @@ fn iter2<U, T>(v1: [U]/&, v2: [T]/&, f: fn(U, T)) {
assert
1u
<=
nn
;
vec
::
iteri
(
xx
,
{|
ii
,
_
x
|
let
len
=
vec
::
len
(
xx
);
if
ii
+
nn
<=
len
{
ww
+=
[
vec
::
slice
(
xx
,
ii
,
ii
+
nn
)]
/~
;
if
ii
+
nn
<=
len
unchecked
{
vec
::
push
(
ww
,
vec
::
slice
(
xx
,
ii
,
ii
+
nn
))
;
}
});
ret
ww
;
...
...
@@ -2195,10 +2220,10 @@ fn test_connect() {
#[test]
fn
test_windowed
()
{
assert
[[
1u
,
2u
,
3u
]
/~
,[
2u
,
3u
,
4u
]
/~
,[
3u
,
4u
,
5u
]
/~
,[
4u
,
5u
,
6u
]
/~
]
/~
==
windowed
(
3u
,
[
1u
,
2u
,
3u
,
4u
,
5u
,
6u
]
/~
);
==
windowed
(
3u
,
[
1u
,
2u
,
3u
,
4u
,
5u
,
6u
]
/~
);
assert
[[
1u
,
2u
,
3u
,
4u
]
/~
,[
2u
,
3u
,
4u
,
5u
]
/~
,[
3u
,
4u
,
5u
,
6u
]
/~
]
/~
==
windowed
(
4u
,
[
1u
,
2u
,
3u
,
4u
,
5u
,
6u
]
/~
);
==
windowed
(
4u
,
[
1u
,
2u
,
3u
,
4u
,
5u
,
6u
]
/~
);
assert
[]
/~
==
windowed
(
7u
,
[
1u
,
2u
,
3u
,
4u
,
5u
,
6u
]
/~
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录