Bug 532088 - avoid using String(String) or String(String.substring())

1) The String.substring() in 1.4 kept original char[] reference in the
new String, which was of course not good. In 1.8+ it always copies the
portion of char array.

So all constructs can be safely changed:

new String(s.substring(x)) -> s.substring(x)
new String(s.substring(x,y)) -> s.substring(x,y)

2) String(String) in 1.4 copied the original char array if the size was
different, so by new String(String) one tried to avoid memory leaks. In
1.8+ new String(String) simply reuses the original pointers, so no gain
here and we create new (wasted) String reference.

So except few places where a *different* String *pointer* is required,
all constructs can be safely changed:

new String(string) -> string
new String(stringBuffer.toString()) -> stringBuffer.toString()

Change-Id: I061d1a82185605d0fba16a8885752d5da948ed20
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
13 files changed
tree: 0eadefb6b651cbeba45246a034101bee4a9261bc
  1. modules/
  2. org.eclipse.jdt.annotation/
  3. org.eclipse.jdt.annotation_v1/
  4. org.eclipse.jdt.apt.core/
  5. org.eclipse.jdt.apt.pluggable.core/
  6. org.eclipse.jdt.apt.pluggable.tests/
  7. org.eclipse.jdt.apt.tests/
  8. org.eclipse.jdt.apt.ui/
  9. org.eclipse.jdt.compiler.apt/
  10. org.eclipse.jdt.compiler.apt.tests/
  11. org.eclipse.jdt.compiler.tool/
  12. org.eclipse.jdt.compiler.tool.tests/
  13. org.eclipse.jdt.core/
  14. org.eclipse.jdt.core.ecj.validation/
  15. org.eclipse.jdt.core.internal.tools/
  16. org.eclipse.jdt.core.tests.builder/
  17. org.eclipse.jdt.core.tests.compiler/
  18. org.eclipse.jdt.core.tests.model/
  19. org.eclipse.jdt.core.tests.performance/
  20. tests-pom/
  21. .gitignore
  22. pom.xml
  23. README.md
README.md

JDT Core

This is the core part of Eclipse's Java development tools. It contains the non-UI support for compiling and working with Java code, including the following:

  • an incremental or batch Java compiler that can run standalone or as part of the Eclipse IDE
  • Java source and class file indexer and search infrastructure
  • a Java source code formatter
  • APIs for code assist, access to the AST and structured manipulation of Java source.

For more information, refer to the [JDT wiki page] 1 or the [JDT project overview page] 2.

License

Eclipse Public License (EPL) v1.0