@SuppressWarnings("unchecked")
    public final void allocateStack(int len) {

        length = len;
        /*
         * We allocate a temp array of half the size of the array to sort.
         * the original implementation had a 256 maximum size for this and made 
         * the temp array grow on demand.
         * 
         * Timsort consumes half the size of the original array to merge at WORST.
         * But considering we use the same temp array over and over across frames,
         * there is a good chance we will stumble upon the worst-case scenario at one
         * time or another.
         * So we use half of the original array size.
         */        
        int tmpLen = len >>> 1;
     
        //if the array is null or tmpLen is above the actual length we allocate the array
        if (tmpArray == null || tmpLen > tmpArray.length) {
            //has to use Object for temp storage
            tmpArray = (T[]) new Object[tmpLen];         
        }

        /*
         * This part was taken from the Java7 TimSort.
         * The original implementation use a stack of length 85, but this seems 
         * to boost performance for mid-sized arrays.
         * I changed the numbers so they fit our MIN_SIZE parameter.
         * 
         * Those numbers can be computed using this formula : 
         * MIN_SIZE * 1.618^n = N
         * Where n is the size of the stack, and N the number element of the array to sort        
         * If MIN_SIZE is changed you have to recompute those values.
         */
        int stackLen = (len < 1400 ? 5
                : len < 15730 ? 10
                : len < 1196194 ? 19 : 40);

        //Same remark as with the temp array
        if (runsIndices == null || stackLen > runsIndices.length) {
            runsIndices = new int[stackLen];
            runsLength = new int[stackLen];           
        }
    }
Allocate temp variables for the given length This method should be called
at least once, but only if the length of the list to sort changed before
sorting

@param len the size of the array to sort
jme3-core/src/main/java/com/jme3/util/ListSort.java