Get rid of the unseemly reinterpret_casts in build_sized implementations. Closes #3272.
This commit is contained in:
parent
b2aeb31451
commit
c87e9a5815
2 changed files with 4 additions and 16 deletions
|
@ -52,14 +52,8 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
|
|||
#[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 @@ pure fn from_slice<T: copy>(t: &[T]) -> ~[T] {
|
|||
#[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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue