package kotlin.jvm.internal; import kotlin.collections.IntIterator; import kotlin.ranges.IntRange; /* loaded from: classes5.dex */ public abstract class PrimitiveSpreadBuilder { private int position; private final int size; private final T[] spreads; private static /* synthetic */ void getSpreads$annotations() { } public final int getPosition() { return this.position; } public abstract int getSize(T t); public final void setPosition(int i) { this.position = i; } public PrimitiveSpreadBuilder(int i) { this.size = i; this.spreads = (T[]) new Object[i]; } public final void addSpread(T spreadArgument) { Intrinsics.checkNotNullParameter(spreadArgument, "spreadArgument"); T[] tArr = this.spreads; int i = this.position; this.position = i + 1; tArr[i] = spreadArgument; } public final int size() { int i = 0; IntIterator it = new IntRange(0, this.size - 1).iterator(); while (it.hasNext()) { T t = this.spreads[it.nextInt()]; i += t != null ? getSize(t) : 1; } return i; } public final T toArray(T values, T result) { Intrinsics.checkNotNullParameter(values, "values"); Intrinsics.checkNotNullParameter(result, "result"); IntIterator it = new IntRange(0, this.size - 1).iterator(); int i = 0; int i2 = 0; while (it.hasNext()) { int nextInt = it.nextInt(); T t = this.spreads[nextInt]; if (t != null) { if (i < nextInt) { int i3 = nextInt - i; System.arraycopy(values, i, result, i2, i3); i2 += i3; } int size = getSize(t); System.arraycopy(t, 0, result, i2, size); i2 += size; i = nextInt + 1; } } int i4 = this.size; if (i < i4) { System.arraycopy(values, i, result, i2, i4 - i); } return result; } }