Skip to content

Commit 68e9aa5

Browse files
committed
Make at_vec push functions more like the current vec ones.
1 parent 519deca commit 68e9aa5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/libcore/at_vec.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,33 @@ mod unsafe {
131131
(**repr).fill = new_len * sys::size_of::<T>();
132132
}
133133

134-
/// Append an element to a vector
135134
#[inline(always)]
136135
unsafe fn push<T>(&v: @[const T], +initval: T) {
137136
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
138137
let fill = (**repr).fill;
139138
if (**repr).alloc > fill {
140-
(**repr).fill += sys::size_of::<T>();
141-
let p = addr_of((**repr).data);
142-
let p = ptr::offset(p, fill) as *mut T;
143-
rusti::move_val_init(*p, initval);
139+
push_fast(v, initval);
144140
}
145141
else {
146142
push_slow(v, initval);
147143
}
148144
}
145+
// This doesn't bother to make sure we have space.
146+
#[inline(always)] // really pretty please
147+
unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
148+
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
149+
let fill = (**repr).fill;
150+
(**repr).fill += sys::size_of::<T>();
151+
let p = ptr::addr_of((**repr).data);
152+
let p = ptr::offset(p, fill) as *mut T;
153+
rusti::move_val_init(*p, initval);
154+
}
155+
149156
unsafe fn push_slow<T>(&v: @[const T], +initval: T) {
150157
reserve_at_least(v, v.len() + 1u);
151-
push(v, initval);
158+
push_fast(v, initval);
152159
}
160+
153161
/**
154162
* Reserves capacity for exactly `n` elements in the given vector.
155163
*

0 commit comments

Comments
 (0)