News for hackers. Stuff that matters.
Re:Rust Language Cheat Sheet by kevincox on Sunday April 25, 2021 @01:11PM (#26934384)
String concatenation isn't expensive in Rust. Since the + operator consumes the first argument it will reuse the buffer and allocate quadratically. The only possible performance downside is that it can't count all of the lengths in advance and do a single allocation.
Re:Rust Language Cheat Sheet by estebank on Sunday April 25, 2021 @02:01PM (#26934906)
Add<&str> for String in a loop isn't as problematic as adding two, for example, Java Strings because of the capacity growth curve and buffer reuse, but it is still worse than not having a `String::with_capacity` call before the loop. I am sad to see that clippy doesn't have any lints for this, but I can see how it would be hard to make a general good suggestion for it.
Re:Rust Language Cheat Sheet by talideon on Monday April 26, 2021 @07:00AM (#26941245)
Keep in mind that the potential expense of string concatenation was only _one_ example.

There's a reason why I explicitly mentioned immutability: Rust's `String` type has more in common with C#'s `StringBuilder` class than it does with strings in most languages. Meanwhile, the behavour of str/&str is very different.