private Buffer ensureCapacity(int minCapacity) {
            if (tmpLength < minCapacity) {
                // Compute smallest power of 2 > minCapacity
                int newSize = minCapacity;
                newSize |= newSize >> 1;
                newSize |= newSize >> 2;
                newSize |= newSize >> 4;
                newSize |= newSize >> 8;
                newSize |= newSize >> 16;
                newSize++;

                if (newSize < 0) // Not bloody likely!
                    newSize = minCapacity;
                else
                    newSize = Math.min(newSize, aLength >>> 1);

                tmp = s.allocate(newSize);
                tmpLength = newSize;
            }
            return tmp;
        }
Ensures that the external array tmp has at least the specified
number of elements, increasing its size if necessary.  The size
increases exponentially to ensure amortized linear time complexity.

@param minCapacity the minimum required capacity of the tmp array
@return tmp, whether or not it grew
indexr-query-opt/src/main/java/org/apache/spark/util/collection/TimSort.java