You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically the idea is that, for impl FromIterator<String> for String, we reimplement it slightly so that newly returned string reuses and reallocates the buffer of the first string in the iterator. It would look something like this:
fn from_iter(iter: I) -> String {
match iter.next() {
None => String::new(),
Some(base) => { base.extend(iter); base }
}
}
Of course, this might not be worth the added complexity– in particular, I'm not sure what the implications are for added branching– so I'm writing this issue to solicit any feedback before creating a PR.
The text was updated successfully, but these errors were encountered:
I think that it will likely be a reallocation + move which is basically as expensive as allocating a brand new string. Thus this doesn't sound high priority to me; but maybe worth trying :)
Hmm, I agree that in general it's unlikely that the first string happens to have enough capacity for the whole iterator, so this might be of minimal value in general.
It would, however, be a clear win for a case where there happens to only be one element in the iterator, though, so might be worth doing for that alone.
Uh oh!
There was an error while loading. Please reload this page.
rust/src/liballoc/string.rs
Lines 1720 to 1727 in 07c415c
Basically the idea is that, for
impl FromIterator<String> for String
, we reimplement it slightly so that newly returned string reuses and reallocates the buffer of the first string in the iterator. It would look something like this:Of course, this might not be worth the added complexity– in particular, I'm not sure what the implications are for added branching– so I'm writing this issue to solicit any feedback before creating a PR.
The text was updated successfully, but these errors were encountered: