@VisibleForTesting long validateReallocation(long newSize) { int saturatedSize = saturatedArraySizeCast(newSize); if (saturatedSize <= capacity()) throw new RuntimeException(); return saturatedSize; }
@VisibleForTesting long calculateNewSize(long count) { long capacity = capacity(); //Both sides of this max expression need to use long arithmetic to avoid integer overflow //count and capacity are longs so that ensures it right now. long newSize = capacity + count; //For large buffers don't double, increase by 50% if (capacity > 1024L * 1024L * DOUBLING_THRESHOLD) newSize = Math.max((capacity * 3L) / 2L, newSize); else newSize = Math.max(capacity * 2L, newSize); return validateReallocation(newSize); }
@VisibleForTesting long validateReallocation(long newSize) { int saturatedSize = saturatedArraySizeCast(newSize); if (saturatedSize <= capacity()) throw new RuntimeException(); return saturatedSize; }
@VisibleForTesting long validateReallocation(long newSize) { int saturatedSize = saturatedArraySizeCast(newSize); if (saturatedSize <= capacity()) throw new RuntimeException(); return saturatedSize; }
@VisibleForTesting long calculateNewSize(long count) { long capacity = capacity(); //Both sides of this max expression need to use long arithmetic to avoid integer overflow //count and capacity are longs so that ensures it right now. long newSize = capacity + count; //For large buffers don't double, increase by 50% if (capacity > 1024L * 1024L * DOUBLING_THRESHOLD) newSize = Math.max((capacity * 3L) / 2L, newSize); else newSize = Math.max(capacity * 2L, newSize); return validateReallocation(newSize); }
@VisibleForTesting long validateReallocation(long newSize) { int saturatedSize = saturatedArraySizeCast(newSize); if (saturatedSize <= capacity()) throw new RuntimeException(); return saturatedSize; }
@VisibleForTesting long calculateNewSize(long count) { long capacity = capacity(); //Both sides of this max expression need to use long arithmetic to avoid integer overflow //count and capacity are longs so that ensures it right now. long newSize = capacity + count; //For large buffers don't double, increase by 50% if (capacity > 1024L * 1024L * DOUBLING_THRESHOLD) newSize = Math.max((capacity * 3L) / 2L, newSize); else newSize = Math.max(capacity * 2L, newSize); return validateReallocation(newSize); }
@VisibleForTesting long calculateNewSize(long count) { long capacity = capacity(); //Both sides of this max expression need to use long arithmetic to avoid integer overflow //count and capacity are longs so that ensures it right now. long newSize = capacity + count; //For large buffers don't double, increase by 50% if (capacity > 1024L * 1024L * DOUBLING_THRESHOLD) newSize = Math.max((capacity * 3L) / 2L, newSize); else newSize = Math.max(capacity * 2L, newSize); return validateReallocation(newSize); }