Skip to content

Commit 5e7b666

Browse files
committed
std: update str.push_byte to work without str trailing nulls
1 parent 8567611 commit 5e7b666

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/libstd/str.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,15 +1064,24 @@ pub mod raw {
10641064
}
10651065

10661066
/// Appends a byte to a string. (Not UTF-8 safe).
1067+
#[cfg(stage0)]
10671068
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
10681069
let new_len = s.len() + 1;
10691070
s.reserve_at_least(new_len);
10701071
do s.as_mut_buf |buf, len| {
1071-
*ptr::mut_offset(buf, (len-1) as int) = b;
1072+
*ptr::mut_offset(buf, len as int) = b;
10721073
}
10731074
set_len(&mut *s, new_len);
10741075
}
10751076

1077+
/// Appends a byte to a string. (Not UTF-8 safe).
1078+
#[cfg(not(stage0))]
1079+
#[inline]
1080+
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
1081+
let v: &mut ~[u8] = cast::transmute(s);
1082+
v.push(b);
1083+
}
1084+
10761085
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
10771086
unsafe fn push_bytes(s: &mut ~str, bytes: &[u8]) {
10781087
let new_len = s.len() + bytes.len();

0 commit comments

Comments
 (0)