Handle container builders capacity overflow
This commit is contained in:
committed by
Space
parent
f8bcba0b76
commit
cca5f82aa0
@@ -178,6 +178,7 @@ internal class ListBuilder<E> private constructor(
|
||||
|
||||
private fun ensureCapacity(minCapacity: Int) {
|
||||
if (backing != null) throw IllegalStateException() // just in case somebody casts subList to ListBuilder
|
||||
if (minCapacity < 0) throw OutOfMemoryError() // overflow
|
||||
if (minCapacity > array.size) {
|
||||
val newSize = ArrayDeque.newCapacity(array.size, minCapacity)
|
||||
array = array.copyOfUninitializedElements(newSize)
|
||||
|
||||
@@ -177,6 +177,7 @@ internal class MapBuilder<K, V> private constructor(
|
||||
}
|
||||
|
||||
private fun ensureCapacity(capacity: Int) {
|
||||
if (capacity < 0) throw OutOfMemoryError() // overflow
|
||||
if (capacity > this.capacity) {
|
||||
var newSize = this.capacity * 3 / 2
|
||||
if (capacity > newSize) newSize = capacity
|
||||
|
||||
Reference in New Issue
Block a user