libcore: rewrite str::reserve in pure rust.

This commit is contained in:
Erick Tryzelaar
2012-08-27 07:23:55 -07:00
parent 9074d9b581
commit 628b946186
3 changed files with 3 additions and 15 deletions

View File

@@ -115,11 +115,6 @@ export
StrSlice,
UniqueStr;
#[abi = "cdecl"]
extern mod rustrt {
fn str_reserve_shared(&ss: ~str, nn: libc::size_t);
}
/*
Section: Creating a string
*/
@@ -1818,8 +1813,9 @@ pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
* * n - The number of bytes to reserve space for
*/
fn reserve(&s: ~str, n: uint) {
if capacity(s) < n {
rustrt::str_reserve_shared(s, n as size_t);
unsafe {
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
vec::reserve(*v, n + 1);
}
}