2 ms·
I think the best answer is to take the size of the parent and child strings into account. If the parent is 1M and the child is just a few bytes then make a cop
by ape4 13y ago
I think the best answer is to take the size of the parent and child strings into account. If the parent is 1M and the child is just a few bytes then make a copy so the parent can be freed up. Otherwise use the old behavior.
- boomzilla 13y agoYeah, I don't understand why the JDK dev did not take this approach. Even better, they can add a new API that allows developers specify the implementation that fits better. Something like String.substr(..., boolean allocateSpace) that defaults to the original behavior of substr.
- enjo 13y agoThat'd be even worse. Now I have yet another variable to deal with when tracking down performance issues in my code. One that would be non-obvious to anyone not terribly familiar with how things are working behind the scenes. Better would be to introduce a methods that explicitly exposes the type of substring method being used.
- ape4 13y agoBut you wouldn't have to track down performance issues in your code if it never was slow ;)