You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
borrow relevant parts of AOSP commit dbee9bb342cdfaa5155b1918f90262c05e2464cb
Our SVG-based VectorDrawable implementation still relies on `getDefaultColor` but exceptions are no longer thrown when parsing VectorDrawable xml files which use gradients as colors.
This commit is contained in:
@@ -27,6 +27,7 @@ package com.android.internal.util;
|
||||
* @hide
|
||||
*/
|
||||
public final class GrowingArrayUtils {
|
||||
|
||||
/**
|
||||
* Appends an element to the end of the array, growing the array if there is no more room.
|
||||
* @param array The array to which to append the element. This must NOT be null.
|
||||
@@ -38,10 +39,11 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static <T> T[] append(T[] array, int currentSize, T element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 > array.length) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] newArray = ArrayUtils.newUnpaddedArray(
|
||||
(Class<T>) array.getClass().getComponentType(), growSize(currentSize));
|
||||
(Class<T>)array.getClass().getComponentType(), growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, currentSize);
|
||||
array = newArray;
|
||||
}
|
||||
@@ -54,6 +56,7 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static int[] append(int[] array, int currentSize, int element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 > array.length) {
|
||||
int[] newArray = ArrayUtils.newUnpaddedIntArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, currentSize);
|
||||
@@ -68,6 +71,7 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static long[] append(long[] array, int currentSize, long element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 > array.length) {
|
||||
long[] newArray = ArrayUtils.newUnpaddedLongArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, currentSize);
|
||||
@@ -82,6 +86,7 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static boolean[] append(boolean[] array, int currentSize, boolean element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 > array.length) {
|
||||
boolean[] newArray = ArrayUtils.newUnpaddedBooleanArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, currentSize);
|
||||
@@ -91,6 +96,21 @@ public final class GrowingArrayUtils {
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Primitive float version of {@link #append(Object[], int, Object)}.
|
||||
*/
|
||||
public static float[] append(float[] array, int currentSize, float element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 > array.length) {
|
||||
float[] newArray = ArrayUtils.newUnpaddedFloatArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, currentSize);
|
||||
array = newArray;
|
||||
}
|
||||
array[currentSize] = element;
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element into the array at the specified index, growing the array if there is no
|
||||
* more room.
|
||||
@@ -104,14 +124,16 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static <T> T[] insert(T[] array, int currentSize, int index, T element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 <= array.length) {
|
||||
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
||||
array[index] = element;
|
||||
return array;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] newArray = ArrayUtils.newUnpaddedArray((Class<T>)array.getClass().getComponentType(),
|
||||
growSize(currentSize));
|
||||
growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, index);
|
||||
newArray[index] = element;
|
||||
System.arraycopy(array, index, newArray, index + 1, array.length - index);
|
||||
@@ -123,11 +145,13 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static int[] insert(int[] array, int currentSize, int index, int element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 <= array.length) {
|
||||
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
||||
array[index] = element;
|
||||
return array;
|
||||
}
|
||||
|
||||
int[] newArray = ArrayUtils.newUnpaddedIntArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, index);
|
||||
newArray[index] = element;
|
||||
@@ -140,11 +164,13 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static long[] insert(long[] array, int currentSize, int index, long element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 <= array.length) {
|
||||
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
||||
array[index] = element;
|
||||
return array;
|
||||
}
|
||||
|
||||
long[] newArray = ArrayUtils.newUnpaddedLongArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, index);
|
||||
newArray[index] = element;
|
||||
@@ -157,11 +183,13 @@ public final class GrowingArrayUtils {
|
||||
*/
|
||||
public static boolean[] insert(boolean[] array, int currentSize, int index, boolean element) {
|
||||
assert currentSize <= array.length;
|
||||
|
||||
if (currentSize + 1 <= array.length) {
|
||||
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
||||
array[index] = element;
|
||||
return array;
|
||||
}
|
||||
|
||||
boolean[] newArray = ArrayUtils.newUnpaddedBooleanArray(growSize(currentSize));
|
||||
System.arraycopy(array, 0, newArray, 0, index);
|
||||
newArray[index] = element;
|
||||
@@ -177,6 +205,7 @@ public final class GrowingArrayUtils {
|
||||
public static int growSize(int currentSize) {
|
||||
return currentSize <= 4 ? 8 : currentSize * 2;
|
||||
}
|
||||
|
||||
// Uninstantiable
|
||||
private GrowingArrayUtils() {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user