Skip to content

Commit

Permalink
In ImmutableDoubleArray and ImmutableLongArray, use Arrays.copyOf whe…
Browse files Browse the repository at this point in the history
…n expanding the internal array.

In ImmutableIntArray, where we already made this change, remove an inconsistent `this.`.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=318294443
  • Loading branch information
eamonnmcmanus authored and kluever committed Jun 30, 2020
1 parent 2814650 commit 689d2b3
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ public Builder addAll(ImmutableDoubleArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
double[] newArray = new double[expandedCapacity(array.length, newCount)];
System.arraycopy(array, 0, newArray, 0, count);
this.array = newArray;
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Builder addAll(ImmutableIntArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
this.array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ public Builder addAll(ImmutableLongArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
long[] newArray = new long[expandedCapacity(array.length, newCount)];
System.arraycopy(array, 0, newArray, 0, count);
this.array = newArray;
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ public Builder addAll(ImmutableDoubleArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
double[] newArray = new double[expandedCapacity(array.length, newCount)];
System.arraycopy(array, 0, newArray, 0, count);
this.array = newArray;
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public Builder addAll(ImmutableIntArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
this.array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ public Builder addAll(ImmutableLongArray values) {
private void ensureRoomFor(int numberToAdd) {
int newCount = count + numberToAdd; // TODO(kevinb): check overflow now?
if (newCount > array.length) {
long[] newArray = new long[expandedCapacity(array.length, newCount)];
System.arraycopy(array, 0, newArray, 0, count);
this.array = newArray;
array = Arrays.copyOf(array, expandedCapacity(array.length, newCount));
}
}

Expand Down

0 comments on commit 689d2b3

Please sign in to comment.