提交 5e7b6662 编写于 作者: E Erick Tryzelaar

std: update str.push_byte to work without str trailing nulls

上级 8567611a
......@@ -1064,15 +1064,24 @@ pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
}
/// Appends a byte to a string. (Not UTF-8 safe).
#[cfg(stage0)]
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
let new_len = s.len() + 1;
s.reserve_at_least(new_len);
do s.as_mut_buf |buf, len| {
*ptr::mut_offset(buf, (len-1) as int) = b;
*ptr::mut_offset(buf, len as int) = b;
}
set_len(&mut *s, new_len);
}
/// Appends a byte to a string. (Not UTF-8 safe).
#[cfg(not(stage0))]
#[inline]
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
let v: &mut ~[u8] = cast::transmute(s);
v.push(b);
}
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
unsafe fn push_bytes(s: &mut ~str, bytes: &[u8]) {
let new_len = s.len() + bytes.len();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册