Skip to content

Commit c87e9a5

Browse files
committed
Get rid of the unseemly reinterpret_casts in build_sized implementations. Closes #3272.
1 parent b2aeb31 commit c87e9a5

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/libcore/at_vec.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,8 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
5252
#[inline(always)]
5353
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
5454
let mut vec = @[];
55-
unsafe {
56-
unsafe::reserve(vec, size);
57-
// This is an awful hack to be able to make the push function
58-
// pure. Is there a better way?
59-
::unsafe::reinterpret_cast::
60-
<fn(push: pure fn(+A)), fn(push: fn(+A))>
61-
(builder)(|+x| unsafe::push(vec, x));
62-
}
55+
unsafe { unsafe::reserve(vec, size); }
56+
builder(|+x| unsafe { unsafe::push(vec, x) });
6357
return vec;
6458
}
6559

src/libcore/vec.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,8 @@ pure fn from_slice<T: copy>(t: &[T]) -> ~[T] {
234234
#[inline(always)]
235235
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> ~[A] {
236236
let mut vec = ~[];
237-
unsafe {
238-
reserve(vec, size);
239-
// This is an awful hack to be able to make the push function
240-
// pure. Is there a better way?
241-
::unsafe::reinterpret_cast::
242-
<fn(push: pure fn(+A)), fn(push: fn(+A))>
243-
(builder)(|+x| push(vec, x));
244-
}
237+
unchecked { reserve(vec, size); }
238+
builder(|+x| unchecked { push(vec, x) });
245239
return vec;
246240
}
247241

0 commit comments

Comments
 (0)