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

String#repeat loop optimization

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 11
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b04
    • CPU:
      generic
    • OS:
      generic

      Description

      As suggested by Ivan Gerasimov.

      diff -r dc913ab01067 src/java.base/share/classes/java/lang/String.java
      --- a/src/java.base/share/classes/java/lang/String.java Fri Mar 02 09:40:07 2018 -0400
      +++ b/src/java.base/share/classes/java/lang/String.java Fri Mar 02 10:11:03 2018 -0400
      @@ -3001,9 +3001,8 @@
               final byte[] multiple = new byte[limit];
               System.arraycopy(value, 0, multiple, 0, len);
               int copied = len;
      - for (int next = copied << 1; next < limit && 0 < next; next = next << 1) {
      + for (; copied < limit - copied; copied <<= 1) {
                   System.arraycopy(multiple, 0, multiple, copied, copied);
      - copied = next;
               }
               System.arraycopy(multiple, 0, multiple, copied, limit - copied);
               return new String(multiple, coder);

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlaskey Jim Laskey
                Reporter:
                jlaskey Jim Laskey
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: