4 ms·
Note that this is directly contradicted by another commnent[1] on this post, where three fixed strings are concatenated with +=, yet that was still slower. Per
by BeeOnRope 9y ago
Note that this is directly contradicted by another commnent[1] on this post, where three fixed strings are concatenated with +=, yet that was still slower.
Perhaps the use of += as separate statements is the difference, but one would hope that gc wasn't so fragile as to be unable to identify those sequences as identical.
---
[1] https://news.ycombinator.com/item?id=16533650 https://news.ycombinator.com/item?id=16533650
- lugg 9y agoI suspect / understood that as being the optimization is based on the fact that those are concatenated references and not string literals. I don't quite understand why string literals wouldn't be even easier to optimize but there it is.
- tapirl 9y agoThe optimization made by gc is only valid for the form: s0 + s1 + .... + sn.