@@ -807,13 +807,24 @@ pub fn from_utf16(v: &[u16]) -> ~str {
807807
808808/// Allocates a new string with the specified capacity. The string returned is
809809/// the empty string, but has capacity for much more.
810+ #[ cfg( stage0) ]
810811#[ inline]
811812pub fn with_capacity ( capacity : uint ) -> ~str {
812813 let mut buf = ~"";
813814 buf. reserve ( capacity) ;
814815 buf
815816}
816817
818+ /// Allocates a new string with the specified capacity. The string returned is
819+ /// the empty string, but has capacity for much more.
820+ #[ cfg( not( stage0) ) ]
821+ #[ inline]
822+ pub fn with_capacity ( capacity : uint ) -> ~str {
823+ unsafe {
824+ cast:: transmute ( vec:: with_capacity :: < ~[ u8 ] > ( capacity) )
825+ }
826+ }
827+
817828/// As char_len but for a slice of a string
818829///
819830/// # Arguments
@@ -948,6 +959,14 @@ pub mod raw {
948959 :: cast:: transmute ( v)
949960 }
950961
962+ #[ lang="strdup_uniq" ]
963+ #[ cfg( not( test) ) ]
964+ #[ allow( missing_doc) ]
965+ #[ inline]
966+ pub unsafe fn strdup_uniq ( ptr : * u8 , len : uint ) -> ~str {
967+ from_buf_len ( ptr, len)
968+ }
969+
951970 /// Create a Rust string from a null-terminated C string
952971 pub unsafe fn from_c_str ( buf : * libc:: c_char ) -> ~str {
953972 let mut curr = buf;
@@ -3700,7 +3719,7 @@ mod tests {
37003719#[cfg(test)]
37013720mod bench {
37023721 use extra::test::BenchHarness;
3703- use str ;
3722+ use super::* ;
37043723
37053724 #[bench]
37063725 fn is_utf8_100_ascii(bh: &mut BenchHarness) {
@@ -3710,7 +3729,7 @@ mod bench {
37103729
37113730 assert_eq!(100, s.len());
37123731 do bh.iter {
3713- str:: is_utf8(s);
3732+ is_utf8(s);
37143733 }
37153734 }
37163735
@@ -3719,7 +3738,7 @@ mod bench {
37193738 let s = bytes!(" 𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
37203739 assert_eq!(100, s.len());
37213740 do bh.iter {
3722- str:: is_utf8(s);
3741+ is_utf8(s);
37233742 }
37243743 }
37253744
@@ -3742,4 +3761,11 @@ mod bench {
37423761 s. map_chars( |c| ( ( c as uint) + 1 ) as char ) ;
37433762 }
37443763 }
3764+
3765+ #[ bench]
3766+ fn bench_with_capacity( bh: & mut BenchHarness ) {
3767+ do bh. iter {
3768+ with_capacity( 100 ) ;
3769+ }
3770+ }
37453771}
0 commit comments