RFR: 8276926: Use String.valueOf() when initializing File.separator and File.pathSeparator
Сергей Цыпанов
duke at openjdk.java.net
Wed Nov 10 09:29:57 UTC 2021
Looking into File.pathSeparator I've found out that currently we initialize them as
public static final String separator = "" + separatorChar;
Which after compilation turns into
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder.<init> ()V
LDC ""
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
GETSTATIC java/io/File.pathSeparatorChar : C
INVOKEVIRTUAL java/lang/StringBuilder.append (C)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
PUTSTATIC java/io/File.pathSeparator : Ljava/lang/String;
This can be simplified to
public static final String separator = String.valueOf(separatorChar);
Which is in turn complied into more compact
GETSTATIC java/io/File.pathSeparatorChar : C
INVOKESTATIC java/lang/String.valueOf (C)Ljava/lang/String;
PUTSTATIC java/io/File.pathSeparator : Ljava/lang/String;
The changed code is likely to slightly improve start-up time as it allocates less and does no bound checks.
-------------
Commit messages:
- 8276926: Use String.valueOf() when initializing File.separator and File.pathSeparator
Changes: https://git.openjdk.java.net/jdk/pull/6326/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6326&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8276926
Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 mod
Patch: https://git.openjdk.java.net/jdk/pull/6326.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/6326/head:pull/6326
PR: https://git.openjdk.java.net/jdk/pull/6326
More information about the core-libs-dev
mailing list