diff --git a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArray.java b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArray.java index 02d8aad034..6efe3d74a5 100644 --- a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArray.java +++ b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArray.java @@ -1,13 +1,15 @@ package com.google.android.exoplayer2.extractor.avi; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import java.util.Arrays; public class UnboundedIntArray { @NonNull + @VisibleForTesting int[] array; //unint - int size =0; + private int size =0; public UnboundedIntArray() { this(8); @@ -32,7 +34,9 @@ public class UnboundedIntArray { } public void pack() { - array = Arrays.copyOf(array, size); + if (size != array.length) { + array = Arrays.copyOf(array, size); + } } protected void grow() { @@ -40,6 +44,11 @@ public class UnboundedIntArray { array = Arrays.copyOf(array, increase + array.length + size); } + public int[] getArray() { + pack(); + return array; + } + /** * Only works if values are in sequential order * @param v diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java index 2f0f9078e4..b3db043918 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java @@ -9,7 +9,7 @@ public class UnboundedIntArrayTest { final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(); unboundedIntArray.add(4); Assert.assertEquals(1, unboundedIntArray.getSize()); - Assert.assertEquals(unboundedIntArray.array[0], 4); + Assert.assertEquals(unboundedIntArray.getArray()[0], 4); } @Test