Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocations when joining strings #7776

Merged
merged 2 commits into from Sep 29, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Make util::str::str_join operate on Iterators

  • Loading branch information
frewsxcv committed Sep 28, 2015
commit 2857e547be606cbed1e5db060d254116223b7723
@@ -326,8 +326,10 @@ pub unsafe fn c_str_to_string(s: *const c_char) -> String {
from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
}

pub fn str_join<T: AsRef<str>>(strs: &[T], join: &str) -> String {
strs.iter().fold(String::new(), |mut acc, s| {
pub fn str_join<I, T>(strs: I, join: &str) -> String
where I: IntoIterator<Item=T>, T: AsRef<str>,
{
strs.into_iter().fold(String::new(), |mut acc, s| {
if !acc.is_empty() { acc.push_str(join); }
acc.push_str(s.as_ref());
acc
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.