jdk/src/java.base/share/classes/java/util/TimSort.java
changeset 28971 53e56ca0e39d
parent 28871 d04fa3bde1d0
equal deleted inserted replaced
28970:aaec841a1a3c 28971:53e56ca0e39d
   172          * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
   172          * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
   173          * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
   173          * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
   174          * large) stack lengths for smaller arrays.  The "magic numbers" in the
   174          * large) stack lengths for smaller arrays.  The "magic numbers" in the
   175          * computation below must be changed if MIN_MERGE is decreased.  See
   175          * computation below must be changed if MIN_MERGE is decreased.  See
   176          * the MIN_MERGE declaration above for more information.
   176          * the MIN_MERGE declaration above for more information.
       
   177          * The maximum value of 49 allows for an array up to length
       
   178          * Integer.MAX_VALUE-4, if array is filled by the worst case stack size
       
   179          * increasing scenario. More explanations are given in section 4 of:
       
   180          * http://envisage-project.eu/wp-content/uploads/2015/02/sorting.pdf
   177          */
   181          */
   178         int stackLen = (len <    120  ?  5 :
   182         int stackLen = (len <    120  ?  5 :
   179                         len <   1542  ? 10 :
   183                         len <   1542  ? 10 :
   180                         len < 119151  ? 24 : 49);
   184                         len < 119151  ? 24 : 49);
   181         runBase = new int[stackLen];
   185         runBase = new int[stackLen];