提交 c87e9a58 编写于 作者: M Michael Sullivan

Get rid of the unseemly reinterpret_casts in build_sized implementations. Closes #3272.

上级 b2aeb314
......@@ -52,14 +52,8 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
#[inline(always)]
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
let mut vec = @[];
unsafe {
unsafe::reserve(vec, size);
// This is an awful hack to be able to make the push function
// pure. Is there a better way?
::unsafe::reinterpret_cast::
<fn(push: pure fn(+A)), fn(push: fn(+A))>
(builder)(|+x| unsafe::push(vec, x));
}
unsafe { unsafe::reserve(vec, size); }
builder(|+x| unsafe { unsafe::push(vec, x) });
return vec;
}
......
......@@ -234,14 +234,8 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) {
#[inline(always)]
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> ~[A] {
let mut vec = ~[];
unsafe {
reserve(vec, size);
// This is an awful hack to be able to make the push function
// pure. Is there a better way?
::unsafe::reinterpret_cast::
<fn(push: pure fn(+A)), fn(push: fn(+A))>
(builder)(|+x| push(vec, x));
}
unchecked { reserve(vec, size); }
builder(|+x| unchecked { push(vec, x) });
return vec;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册