Skip to content

Commit

Permalink
Merge pull request #3706 from erickt/str-with-capacity
Browse files Browse the repository at this point in the history
libcore: add a str::with_capacity to match the fn in vec
  • Loading branch information
catamorphism committed Oct 17, 2012
2 parents 7f12cc4 + bdc1b7a commit ebce097
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,11 @@ pub pure fn from_utf16(v: &[u16]) -> ~str {
move buf
}

pub pure fn with_capacity(capacity: uint) -> ~str {
let mut buf = ~"";
unsafe { reserve(&mut buf, capacity); }
move buf
}

/**
* As char_len but for a slice of a string
Expand Down

0 comments on commit ebce097

Please sign in to comment.