On Wed, 10 Nov 2021 09:22:32 GMT, Сергей Цыпанов <d...@openjdk.java.net> wrote:

> Looking into `File.pathSeparator` I've found out that currently we initialize 
> it 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.

This pull request has now been integrated.

Changeset: 0f23c6a9
Author:    Sergey Tsypanov <sergei.tsypa...@yandex.ru>
Committer: Claes Redestad <redes...@openjdk.org>
URL:       
https://git.openjdk.java.net/jdk/commit/0f23c6a9feb3657eb20ff5988a9e2ffca2108af1
Stats:     2 lines in 1 file changed: 0 ins; 0 del; 2 mod

8276926: Use String.valueOf() when initializing File.separator and 
File.pathSeparator

Reviewed-by: redestad, jlaskey

-------------

PR: https://git.openjdk.java.net/jdk/pull/6326

Reply via email to