mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
libcore: Rewrite str::unsafe::push_byte in pure rust.
This commit is contained in:
parent
94c3975a9a
commit
7bb65848a1
@ -117,7 +117,6 @@ export
|
|||||||
|
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
extern mod rustrt {
|
extern mod rustrt {
|
||||||
fn rust_str_push(&s: ~str, ch: u8);
|
|
||||||
fn str_reserve_shared(&ss: ~str, nn: libc::size_t);
|
fn str_reserve_shared(&ss: ~str, nn: libc::size_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1998,12 +1997,18 @@ mod unsafe {
|
|||||||
|
|
||||||
/// Appends a byte to a string. (Not UTF-8 safe).
|
/// Appends a byte to a string. (Not UTF-8 safe).
|
||||||
unsafe fn push_byte(&s: ~str, b: u8) {
|
unsafe fn push_byte(&s: ~str, b: u8) {
|
||||||
rustrt::rust_str_push(s, b);
|
reserve_at_least(s, s.len() + 1);
|
||||||
|
do as_buf(s) |buf, len| {
|
||||||
|
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
|
||||||
|
*ptr::mut_offset(buf, len) = b;
|
||||||
|
}
|
||||||
|
set_len(s, s.len() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
||||||
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
||||||
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
|
reserve_at_least(s, s.len() + bytes.len());
|
||||||
|
for vec::each(bytes) |byte| { push_byte(s, byte); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
||||||
|
@ -148,16 +148,6 @@ str_reserve_shared(rust_vec_box** sp,
|
|||||||
reserve_vec_exact(task, sp, n_elts + 1);
|
reserve_vec_exact(task, sp, n_elts + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
|
||||||
rust_str_push(rust_vec_box** sp, uint8_t byte) {
|
|
||||||
rust_task *task = rust_get_current_task();
|
|
||||||
size_t fill = (*sp)->body.fill;
|
|
||||||
reserve_vec(task, sp, fill + 1);
|
|
||||||
(*sp)->body.data[fill-1] = byte;
|
|
||||||
(*sp)->body.data[fill] = 0;
|
|
||||||
(*sp)->body.fill = fill + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" CDECL rust_vec*
|
extern "C" CDECL rust_vec*
|
||||||
rand_seed() {
|
rand_seed() {
|
||||||
size_t size = sizeof(ub4) * RANDSIZ;
|
size_t size = sizeof(ub4) * RANDSIZ;
|
||||||
|
@ -38,7 +38,6 @@ rust_getcwd
|
|||||||
rust_get_stdin
|
rust_get_stdin
|
||||||
rust_get_stdout
|
rust_get_stdout
|
||||||
rust_get_stderr
|
rust_get_stderr
|
||||||
rust_str_push
|
|
||||||
rust_list_files
|
rust_list_files
|
||||||
rust_log_console_on
|
rust_log_console_on
|
||||||
rust_log_console_off
|
rust_log_console_off
|
||||||
|
Loading…
Reference in New Issue
Block a user