Skip to content

Commit d5f5391

Browse files
klueverGoogle Java Core Libraries
authored andcommitted
inline calls to checked math operations (to use JDK APIs).
RELNOTES=n/a PiperOrigin-RevId: 801495847
1 parent 8d0b1e4 commit d5f5391

File tree

10 files changed

+10
-18
lines changed

10 files changed

+10
-18
lines changed

android/guava/src/com/google/common/collect/CartesianList.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.annotations.GwtCompatible;
2020
import com.google.common.annotations.GwtIncompatible;
2121
import com.google.common.annotations.J2ktIncompatible;
22-
import com.google.common.math.IntMath;
2322
import java.util.AbstractList;
2423
import java.util.List;
2524
import java.util.ListIterator;
@@ -55,7 +54,7 @@ static <E> List<List<E>> create(List<? extends List<? extends E>> lists) {
5554
axesSizeProduct[axes.size()] = 1;
5655
try {
5756
for (int i = axes.size() - 1; i >= 0; i--) {
58-
axesSizeProduct[i] = IntMath.checkedMultiply(axesSizeProduct[i + 1], axes.get(i).size());
57+
axesSizeProduct[i] = Math.multiplyExact(axesSizeProduct[i + 1], axes.get(i).size());
5958
}
6059
} catch (ArithmeticException e) {
6160
throw new IllegalArgumentException(

android/guava/src/com/google/common/collect/ConcurrentHashMultiset.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.annotations.J2ktIncompatible;
3030
import com.google.common.annotations.VisibleForTesting;
3131
import com.google.common.collect.Serialization.FieldSetter;
32-
import com.google.common.math.IntMath;
3332
import com.google.common.primitives.Ints;
3433
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3534
import com.google.j2objc.annotations.WeakOuter;
@@ -225,7 +224,7 @@ public int add(E element, int occurrences) {
225224
int oldValue = existingCounter.get();
226225
if (oldValue != 0) {
227226
try {
228-
int newValue = IntMath.checkedAdd(oldValue, occurrences);
227+
int newValue = Math.addExact(oldValue, occurrences);
229228
if (existingCounter.compareAndSet(oldValue, newValue)) {
230229
// newValue can't == 0, so no need to check & remove
231230
return oldValue;

android/guava/src/com/google/common/collect/MinMaxPriorityQueue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.annotations.GwtCompatible;
3030
import com.google.common.annotations.J2ktIncompatible;
3131
import com.google.common.annotations.VisibleForTesting;
32-
import com.google.common.math.IntMath;
3332
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3433
import com.google.j2objc.annotations.Weak;
3534
import com.google.j2objc.annotations.WeakOuter;
@@ -968,7 +967,7 @@ private void growIfNeeded() {
968967
private int calculateNewCapacity() {
969968
int oldCapacity = queue.length;
970969
int newCapacity =
971-
(oldCapacity < 64) ? (oldCapacity + 1) * 2 : IntMath.checkedMultiply(oldCapacity / 2, 3);
970+
(oldCapacity < 64) ? (oldCapacity + 1) * 2 : Math.multiplyExact(oldCapacity / 2, 3);
972971
return capAtMaximumSize(newCapacity, maximumSize);
973972
}
974973

android/guava/src/com/google/common/collect/TopKSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private TopKSelector(Comparator<? super T> comparator, int k) {
125125
this.k = k;
126126
checkArgument(k >= 0, "k (%s) must be >= 0", k);
127127
checkArgument(k <= Integer.MAX_VALUE / 2, "k (%s) must be <= Integer.MAX_VALUE / 2", k);
128-
this.buffer = (T[]) new Object[IntMath.checkedMultiply(k, 2)];
128+
this.buffer = (T[]) new Object[Math.multiplyExact(k, 2)];
129129
this.bufferSize = 0;
130130
this.threshold = null;
131131
}

android/guava/src/com/google/common/hash/BloomFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.common.base.Predicate;
2525
import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray;
2626
import com.google.common.math.DoubleMath;
27-
import com.google.common.math.LongMath;
2827
import com.google.common.primitives.SignedBytes;
2928
import com.google.common.primitives.UnsignedBytes;
3029
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -629,7 +628,7 @@ public void writeTo(OutputStream out) throws IOException {
629628
@SuppressWarnings("EnumOrdinal")
630629
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
631630

632-
LockFreeBitArray dataArray = new LockFreeBitArray(LongMath.checkedMultiply(dataLength, 64L));
631+
LockFreeBitArray dataArray = new LockFreeBitArray(Math.multiplyExact(dataLength, 64L));
633632
for (int i = 0; i < dataLength; i++) {
634633
dataArray.putData(i, din.readLong());
635634
}

guava/src/com/google/common/collect/CartesianList.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.annotations.GwtCompatible;
2020
import com.google.common.annotations.GwtIncompatible;
2121
import com.google.common.annotations.J2ktIncompatible;
22-
import com.google.common.math.IntMath;
2322
import java.util.AbstractList;
2423
import java.util.List;
2524
import java.util.ListIterator;
@@ -55,7 +54,7 @@ static <E> List<List<E>> create(List<? extends List<? extends E>> lists) {
5554
axesSizeProduct[axes.size()] = 1;
5655
try {
5756
for (int i = axes.size() - 1; i >= 0; i--) {
58-
axesSizeProduct[i] = IntMath.checkedMultiply(axesSizeProduct[i + 1], axes.get(i).size());
57+
axesSizeProduct[i] = Math.multiplyExact(axesSizeProduct[i + 1], axes.get(i).size());
5958
}
6059
} catch (ArithmeticException e) {
6160
throw new IllegalArgumentException(

guava/src/com/google/common/collect/ConcurrentHashMultiset.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.annotations.J2ktIncompatible;
3030
import com.google.common.annotations.VisibleForTesting;
3131
import com.google.common.collect.Serialization.FieldSetter;
32-
import com.google.common.math.IntMath;
3332
import com.google.common.primitives.Ints;
3433
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3534
import com.google.j2objc.annotations.WeakOuter;
@@ -225,7 +224,7 @@ public int add(E element, int occurrences) {
225224
int oldValue = existingCounter.get();
226225
if (oldValue != 0) {
227226
try {
228-
int newValue = IntMath.checkedAdd(oldValue, occurrences);
227+
int newValue = Math.addExact(oldValue, occurrences);
229228
if (existingCounter.compareAndSet(oldValue, newValue)) {
230229
// newValue can't == 0, so no need to check & remove
231230
return oldValue;

guava/src/com/google/common/collect/MinMaxPriorityQueue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.annotations.GwtCompatible;
3030
import com.google.common.annotations.J2ktIncompatible;
3131
import com.google.common.annotations.VisibleForTesting;
32-
import com.google.common.math.IntMath;
3332
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3433
import com.google.j2objc.annotations.Weak;
3534
import com.google.j2objc.annotations.WeakOuter;
@@ -968,7 +967,7 @@ private void growIfNeeded() {
968967
private int calculateNewCapacity() {
969968
int oldCapacity = queue.length;
970969
int newCapacity =
971-
(oldCapacity < 64) ? (oldCapacity + 1) * 2 : IntMath.checkedMultiply(oldCapacity / 2, 3);
970+
(oldCapacity < 64) ? (oldCapacity + 1) * 2 : Math.multiplyExact(oldCapacity / 2, 3);
972971
return capAtMaximumSize(newCapacity, maximumSize);
973972
}
974973

guava/src/com/google/common/collect/TopKSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private TopKSelector(Comparator<? super T> comparator, int k) {
126126
this.k = k;
127127
checkArgument(k >= 0, "k (%s) must be >= 0", k);
128128
checkArgument(k <= Integer.MAX_VALUE / 2, "k (%s) must be <= Integer.MAX_VALUE / 2", k);
129-
this.buffer = (T[]) new Object[IntMath.checkedMultiply(k, 2)];
129+
this.buffer = (T[]) new Object[Math.multiplyExact(k, 2)];
130130
this.bufferSize = 0;
131131
this.threshold = null;
132132
}

guava/src/com/google/common/hash/BloomFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.common.base.Predicate;
2525
import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray;
2626
import com.google.common.math.DoubleMath;
27-
import com.google.common.math.LongMath;
2827
import com.google.common.primitives.SignedBytes;
2928
import com.google.common.primitives.UnsignedBytes;
3029
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -639,7 +638,7 @@ public void writeTo(OutputStream out) throws IOException {
639638
@SuppressWarnings("EnumOrdinal")
640639
Strategy strategy = BloomFilterStrategies.values()[strategyOrdinal];
641640

642-
LockFreeBitArray dataArray = new LockFreeBitArray(LongMath.checkedMultiply(dataLength, 64L));
641+
LockFreeBitArray dataArray = new LockFreeBitArray(Math.multiplyExact(dataLength, 64L));
643642
for (int i = 0; i < dataLength; i++) {
644643
dataArray.putData(i, din.readLong());
645644
}

0 commit comments

Comments
 (0)