Hacker News new | past | comments | ask | show | jobs | submit login

Rust will actually optimize a chain of string additions to a chain of `push_str`s. This isn't hardcoded, just how addition is implemented.

    fn add(mut self, other: &str) -> String {
        self.push_str(other);
        self
    }
https://github.com/rust-lang/rust/blob/master/src/liballoc/s...

Of course, upfront sizing is still advantageous, but you avoid the pathological n² case.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: