Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8276926

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

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Resolved In Build:
      b24

      Description

      Currently we do it like

      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

      GETSTATIC java/io/File.pathSeparatorChar : C
      INVOKESTATIC java/lang/String.valueOf (C)Ljava/lang/String;
      PUTSTATIC java/io/File.pathSeparator : Ljava/lang/String;

      Which is likely to slightly improve start-up time.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              stsypanov Sergey Tsypanov
              Reporter:
              stsypanov Sergey Tsypanov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: