Unnecessary array copy in AbstractStringBuilder.indexOf(String)? (original) (raw)
Martin Desruisseaux martin.desruisseaux at geomatys.fr
Mon Nov 19 15:46:58 UTC 2012
- Previous message: hg: jdk8/tl/jdk: 8003607: More ProblemList.txt updates (11/2012)
- Next message: (CR#6553074) Unnecessary array copy in AbstractStringBuilder.indexOf(String)?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello all
I noticed that AbstractStringBuilder.indexOf(String, int) is implemented as below:
public int indexOf(String str, int fromIndex) {
return String.indexOf(value, 0, count,
str.toCharArray(), 0, str.length(),
fromIndex); }
The call to str.toCharArray() creates a copy of the String.value char[] array. This copy doesn't seem necessary since the above String.indexOf(...) method doesn't modify the array content. Shouldn't AbstractStringBuilder passes directly the reference to the String internal array instead, maybe using package-privated access to the array?
Admittedly the cloned array is usually small, but the call to indexOf(String, int) is often done in a loop.
Martin
- Previous message: hg: jdk8/tl/jdk: 8003607: More ProblemList.txt updates (11/2012)
- Next message: (CR#6553074) Unnecessary array copy in AbstractStringBuilder.indexOf(String)?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]