diff --git a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt index 786320c6bc9..b823a0f87e2 100644 --- a/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt +++ b/libraries/stdlib/src/kotlin/collections/ArrayDeque.kt @@ -550,12 +550,17 @@ public class ArrayDeque : AbstractMutableList { if (isEmpty()) { structure(head, emptyArray()) - } else if (head < tail) { - @Suppress("UNCHECKED_CAST") - structure(head, elementData.sliceArray(head until tail)) + return + } + + val elements = arrayOfNulls(size) + if (head < tail) { + elementData.copyInto(elements, startIndex = head, endIndex = tail) + structure(head, elements) } else { - @Suppress("UNCHECKED_CAST") - structure(head - elementData.size, elementData.sliceArray(head until elementData.size).plus(elements = elementData.sliceArray(0 until tail))) + elementData.copyInto(elements, startIndex = head) + elementData.copyInto(elements, elementData.size - head, startIndex = 0, endIndex = tail) + structure(head - elementData.size, elements) } } } \ No newline at end of file diff --git a/libraries/stdlib/test/collections/ArrayDequeTest.kt b/libraries/stdlib/test/collections/ArrayDequeTest.kt index 4a67147b823..12244151e9b 100644 --- a/libraries/stdlib/test/collections/ArrayDequeTest.kt +++ b/libraries/stdlib/test/collections/ArrayDequeTest.kt @@ -3,7 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package collections +package test.collections import test.collections.behaviors.iteratorBehavior import test.collections.behaviors.listIteratorBehavior