Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
index 63cb6d77320c2de552f5b849d920ded92800383b..90d6154b154f6a9d1eff7d759ff625ec1bb67098 100644
--- a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
@@ -38,25 +38,27 @@ import java.util.RandomAccess;
/**
* An implementation of {@link FloatList} on top of a primitive array.
- *
+ *
* @author dweis@google.com (Daniel Weis)
*/
-final class FloatArrayList extends AbstractProtobufList<Float> implements FloatList, RandomAccess {
-
+final class FloatArrayList
+ extends AbstractProtobufList<Float>
+ implements FloatList, RandomAccess {
+
private static final FloatArrayList EMPTY_LIST = new FloatArrayList();
static {
EMPTY_LIST.makeImmutable();
}
-
+
public static FloatArrayList emptyList() {
return EMPTY_LIST;
}
-
+
/**
* The backing store for the list.
*/
private float[] array;
-
+
/**
* The size of the list distinct from the length of the array. That is, it is the number of
* elements set in the list.
@@ -71,13 +73,14 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
}
/**
- * Constructs a new mutable {@code FloatArrayList} containing the same elements as {@code other}.
+ * Constructs a new mutable {@code FloatArrayList}
+ * containing the same elements as {@code other}.
*/
- private FloatArrayList(float[] array, int size) {
- this.array = array;
+ private FloatArrayList(float[] other, int size) {
+ array = other;
this.size = size;
}
-
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -90,14 +93,14 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
if (size != other.size) {
return false;
}
-
+
final float[] arr = other.array;
for (int i = 0; i < size; i++) {
if (array[i] != arr[i]) {
return false;
}
}
-
+
return true;
}
@@ -117,7 +120,7 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
}
return new FloatArrayList(Arrays.copyOf(array, capacity), size);
}
-
+
@Override
public Float get(int index) {
return getFloat(index);
@@ -169,7 +172,7 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
}
-
+
if (size < array.length) {
// Shift everything over to make room
System.arraycopy(array, index, array, index + 1, size - index);
@@ -177,10 +180,10 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
// Resize to 1.5x the size
int length = ((size * 3) / 2) + 1;
float[] newArray = new float[length];
-
+
// Copy the first part directly
System.arraycopy(array, 0, newArray, 0, index);
-
+
// Copy the rest shifted over by one to make room
System.arraycopy(array, index, newArray, index + 1, size - index);
array = newArray;
@@ -194,38 +197,38 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
@Override
public boolean addAll(Collection<? extends Float> collection) {
ensureIsMutable();
-
+
if (collection == null) {
throw new NullPointerException();
}
-
+
// We specialize when adding another FloatArrayList to avoid boxing elements.
if (!(collection instanceof FloatArrayList)) {
return super.addAll(collection);
}
-
+
FloatArrayList list = (FloatArrayList) collection;
if (list.size == 0) {
return false;
}
-
+
int overflow = Integer.MAX_VALUE - size;
if (overflow < list.size) {
// We can't actually represent a list this large.
throw new OutOfMemoryError();
}
-
+
int newSize = size + list.size;
if (newSize > array.length) {
array = Arrays.copyOf(array, newSize);
}
-
+
System.arraycopy(list.array, 0, array, size, list.size);
size = newSize;
modCount++;
return true;
}
-
+
@Override
public boolean remove(Object o) {
ensureIsMutable();
@@ -254,7 +257,7 @@ final class FloatArrayList extends AbstractProtobufList<Float> implements FloatL
/**
* Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
* {@link IndexOutOfBoundsException} if it is not.
- *
+ *
* @param index the index to verify is in range
*/
private void ensureIndexInRange(int index) {

Powered by Google App Engine
This is Rietveld 408576698