Several redundant array copies were adressed in JDK-4676426. It seems the one for Character.toString() was missed.
Character.toString() is implemented by using String.valueOf(char[]) but should be implemented with String.valueOf(char) to avoid one allocation of the character array.
Current implementation of Character.toString():
public String toString() {
char buf[] = {value};
return String.valueOf(buf);
}
Suggested implementation:
public String toString() {
return String.valueOf(value);
}
Character.toString() is implemented by using String.valueOf(char[]) but should be implemented with String.valueOf(char) to avoid one allocation of the character array.
Current implementation of Character.toString():
public String toString() {
char buf[] = {value};
return String.valueOf(buf);
}
Suggested implementation:
public String toString() {
return String.valueOf(value);
}
- duplicates
-
JDK-8241649 Optimize Character.toString
- Resolved
- relates to
-
JDK-4676426 redundant array copy in Character.toString(char)
- Resolved