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

Improve URLStreamHandler.parseURL()

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 18
    • None
    • core-libs
    • b10

    Description

      There is an optimization opportunity for the widespread use-case when a resource is read from classpath using getClass().getClassLoader().getResource() or getClass().getClassLoader().getResourceAsStream().

      Pay attention to lines starting from 261. In case I run something like

      var props = getClass().getClassLoader().getResource("some.properties");

      I get into the if-else block starting from 251 and here 'separator' variable is an empty String. In this case we can skip 'separator' from concatenation chain and use String.concat() as there are only two items concatenated.

      In the opposite case 'separator' variable is "/" and at the same time 'ind' variable is -1. This means that expression 'path.substring(0, ind + 1)' always returns empty String and again can be excluded from concatenation chain allowing usage of String.concat().

      In the next else-block, starting from 274, again, String.concat() is applicable for the case we do

      getClassLoader().getResource("file:./config/bootstrap.properties");

      In another if-else block, starting from 277, when id is 0 again path.substring(0, ind) returns empty String making concatenation pointless and avoidable.

      There are also some other minor clean-ups possible regarding constant conditions (lines 252 and 161).

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: