Skip to content

Commit

Permalink
Apply inlinings where possible and appropriate, and suppress elsewhere.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 710066779
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 27, 2024
1 parent 58fb2eb commit a3e17c2
Show file tree
Hide file tree
Showing 54 changed files with 145 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void expectHash(Object object, int hash) {

void replay() {
checkRecording();
equivalentExpectations = equivalentExpectationsBuilder.build();
equivalentExpectations = equivalentExpectationsBuilder.buildOrThrow();
hashExpectations = hashExpectationsBuilder.buildOrThrow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class JoinerBenchmark {
private Iterable<String> components;

@BeforeExperiment
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
void setUp() {
String component = Strings.repeat("a", componentLength);
String[] raw = new String[count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SplitterBenchmark {
private static final Splitter STRING_SPLITTER = Splitter.on("X");

@BeforeExperiment
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
void setUp() {
input = Strings.repeat(text, length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class StringsRepeatBenchmark {
private String originalString;

@BeforeExperiment
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
void setUp() {
originalString = Strings.repeat("x", length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ private void reallyTestNoMatches(CharMatcher matcher, CharSequence s) {
assertEquals(0, matcher.countIn(s));
}

@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
private void reallyTestAllMatches(CharMatcher matcher, CharSequence s) {
assertTrue(matcher.matches(s.charAt(0)));
assertEquals(0, matcher.indexIn(s));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void testReverseReverse() {
assertEquals(converter, converter.reverse().reverse());
}

// We need to test that apply() does in fact behave like convert().
@SuppressWarnings("InlineMeInliner")
public void testApply() {
assertEquals(LONG_VAL, STR_TO_LONG.apply(STR_VAL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public void testFrom() {
Lists.newArrayList(FluentIterable.from(ImmutableList.of(1, 2, 3, 4))));
}

@SuppressWarnings("deprecation") // test of deprecated method
@SuppressWarnings({
"deprecation", // test of deprecated method
// We need to test that from(FluentIterable) really is just a null check.
"InlineMeInliner",
})
public void testFrom_alreadyFluentIterable() {
FluentIterable<Integer> iterable = FluentIterable.from(asList(1));
assertSame(iterable, FluentIterable.from(iterable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ public void testBuilderAddAllHandlesNullsCorrectly() {
}
}

// We need to test that asList() really does return the original list.
@SuppressWarnings("InlineMeInliner")
public void testAsList() {
ImmutableList<String> list = ImmutableList.of("a", "b");
assertSame(list, list.asList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected Table<String, Integer, Character> create(@Nullable Object... data) {
for (int i = 0; i < data.length; i = i + 3) {
builder.put((String) data[i], (Integer) data[i + 1], (Character) data[i + 2]);
}
return builder.build();
return builder.buildOrThrow();
}

// TODO(b/172823566): Use mainline testToImmutableMap once CollectorTester is usable to java7.
Expand All @@ -65,22 +65,22 @@ public void testToImmutableTable_java7_combine() {

public void testBuilder() {
ImmutableTable.Builder<Character, Integer, String> builder = new ImmutableTable.Builder<>();
assertEquals(ImmutableTable.of(), builder.build());
assertEquals(ImmutableTable.of('a', 1, "foo"), builder.put('a', 1, "foo").build());
assertEquals(ImmutableTable.of(), builder.buildOrThrow());
assertEquals(ImmutableTable.of('a', 1, "foo"), builder.put('a', 1, "foo").buildOrThrow());
Table<Character, Integer, String> expectedTable = HashBasedTable.create();
expectedTable.put('a', 1, "foo");
expectedTable.put('b', 1, "bar");
expectedTable.put('a', 2, "baz");
Table<Character, Integer, String> otherTable = HashBasedTable.create();
otherTable.put('b', 1, "bar");
otherTable.put('a', 2, "baz");
assertEquals(expectedTable, builder.putAll(otherTable).build());
assertEquals(expectedTable, builder.putAll(otherTable).buildOrThrow());
}

public void testBuilder_withImmutableCell() {
ImmutableTable.Builder<Character, Integer, String> builder = new ImmutableTable.Builder<>();
assertEquals(
ImmutableTable.of('a', 1, "foo"), builder.put(immutableCell('a', 1, "foo")).build());
ImmutableTable.of('a', 1, "foo"), builder.put(immutableCell('a', 1, "foo")).buildOrThrow());
}

public void testBuilder_withImmutableCellAndNullContents() {
Expand Down Expand Up @@ -127,15 +127,15 @@ public String getValue() {
holder.string = "bar";

// Make sure it uses the original value.
assertEquals(ImmutableTable.of('K', 42, "foo"), builder.build());
assertEquals(ImmutableTable.of('K', 42, "foo"), builder.buildOrThrow());
}

public void testBuilder_noDuplicates() {
ImmutableTable.Builder<Character, Integer, String> builder =
new ImmutableTable.Builder<Character, Integer, String>()
.put('a', 1, "foo")
.put('a', 1, "bar");
assertThrows(IllegalArgumentException.class, () -> builder.build());
assertThrows(IllegalArgumentException.class, () -> builder.buildOrThrow());
}

public void testBuilder_noNulls() {
Expand All @@ -150,7 +150,7 @@ private static <R, C, V> void validateTableCopies(Table<R, C, V> original) {
assertEquals(original, copy);
validateViewOrdering(original, copy);

Table<R, C, V> built = ImmutableTable.<R, C, V>builder().putAll(original).build();
Table<R, C, V> built = ImmutableTable.<R, C, V>builder().putAll(original).buildOrThrow();
assertEquals(original, built);
validateViewOrdering(original, built);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public void testBuilder_orderRowsAndColumnsBy_putAll() {
.orderRowsBy(Ordering.natural())
.orderColumnsBy(Ordering.natural())
.putAll(table)
.build();
.buildOrThrow();
assertThat(copy.rowKeySet()).containsExactly('a', 'b').inOrder();
assertThat(copy.columnKeySet()).containsExactly(1, 2).inOrder();
assertThat(copy.values()).containsExactly("baz", "bar", "foo").inOrder();
Expand All @@ -233,7 +233,7 @@ public void testBuilder_orderRowsAndColumnsBy_sparse() {
builder.put('e', 3, "tub");
builder.put('r', 4, "foo");
builder.put('x', 5, "bar");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.rowKeySet()).containsExactly('b', 'c', 'e', 'r', 'x').inOrder();
assertThat(table.columnKeySet()).containsExactly(0, 1, 2, 3, 4, 5, 7).inOrder();
assertThat(table.values())
Expand All @@ -255,7 +255,7 @@ public void testBuilder_orderRowsAndColumnsBy_dense() {
builder.put('a', 3, "foo");
builder.put('a', 2, "bar");
builder.put('a', 1, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.rowKeySet()).containsExactly('a', 'b', 'c').inOrder();
assertThat(table.columnKeySet()).containsExactly(1, 2, 3).inOrder();
assertThat(table.values())
Expand All @@ -277,7 +277,7 @@ public void testBuilder_orderRowsBy_sparse() {
builder.put('e', 3, "tub");
builder.put('r', 4, "foo");
builder.put('x', 5, "bar");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.rowKeySet()).containsExactly('b', 'c', 'e', 'r', 'x').inOrder();
assertThat(table.column(5).keySet()).containsExactly('e', 'x').inOrder();
}
Expand All @@ -293,7 +293,7 @@ public void testBuilder_orderRowsBy_dense() {
builder.put('a', 3, "foo");
builder.put('a', 2, "bar");
builder.put('a', 1, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.rowKeySet()).containsExactly('a', 'b', 'c').inOrder();
assertThat(table.column(1).keySet()).containsExactly('a', 'b', 'c').inOrder();
}
Expand All @@ -310,7 +310,7 @@ public void testBuilder_orderColumnsBy_sparse() {
builder.put('e', 3, "tub");
builder.put('r', 4, "foo");
builder.put('x', 5, "bar");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.columnKeySet()).containsExactly(0, 1, 2, 3, 4, 5, 7).inOrder();
assertThat(table.row('c').keySet()).containsExactly(0, 3).inOrder();
}
Expand All @@ -326,7 +326,7 @@ public void testBuilder_orderColumnsBy_dense() {
builder.put('a', 3, "foo");
builder.put('a', 2, "bar");
builder.put('a', 1, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table.columnKeySet()).containsExactly(1, 2, 3).inOrder();
assertThat(table.row('c').keySet()).containsExactly(1, 2, 3).inOrder();
}
Expand All @@ -344,7 +344,7 @@ public void testDenseSerialization_manualOrder() {
builder.put('b', 2, "foo");
builder.put('b', 1, "bar");
builder.put('a', 2, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(DenseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -355,7 +355,7 @@ public void testDenseSerialization_rowOrder() {
builder.put('b', 2, "foo");
builder.put('b', 1, "bar");
builder.put('a', 2, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(DenseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -366,7 +366,7 @@ public void testDenseSerialization_columnOrder() {
builder.put('b', 2, "foo");
builder.put('b', 1, "bar");
builder.put('a', 2, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(DenseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -378,7 +378,7 @@ public void testDenseSerialization_bothOrders() {
builder.put('b', 2, "foo");
builder.put('b', 1, "bar");
builder.put('a', 2, "baz");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(DenseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -390,7 +390,7 @@ public void testSparseSerialization_manualOrder() {
builder.put('a', 2, "baz");
builder.put('c', 3, "cat");
builder.put('d', 4, "dog");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(SparseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -403,7 +403,7 @@ public void testSparseSerialization_rowOrder() {
builder.put('a', 2, "baz");
builder.put('c', 3, "cat");
builder.put('d', 4, "dog");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(SparseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -416,7 +416,7 @@ public void testSparseSerialization_columnOrder() {
builder.put('a', 2, "baz");
builder.put('c', 3, "cat");
builder.put('d', 4, "dog");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(SparseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -430,7 +430,7 @@ public void testSparseSerialization_bothOrders() {
builder.put('a', 2, "baz");
builder.put('c', 3, "cat");
builder.put('d', 4, "dog");
Table<Character, Integer, String> table = builder.build();
Table<Character, Integer, String> table = builder.buildOrThrow();
assertThat(table).isInstanceOf(SparseImmutableTable.class);
validateReserialization(table);
}
Expand All @@ -452,6 +452,6 @@ public void testOverflowCondition() {
builder.put(i, 0, "foo");
builder.put(0, i, "bar");
}
assertTrue(builder.build() instanceof SparseImmutableTable);
assertTrue(builder.buildOrThrow() instanceof SparseImmutableTable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class FarmHashFingerprint64Test extends TestCase {
private static final HashFunction HASH_FN = Hashing.farmHashFingerprint64();

// If this test fails, all bets are off
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
public void testReallySimpleFingerprints() {
assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8)));
// 32 characters long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class Fingerprint2011Test extends TestCase {
private static final HashFunction HASH_FN = Hashing.fingerprint2011();

// If this test fails, all bets are off
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
public void testReallySimpleFingerprints() {
assertEquals(8473225671271759044L, fingerprint("test".getBytes(UTF_8)));
// 32 characters long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class MacHashFunctionTest extends TestCase {
.put("HmacSHA1", SHA1_KEY, Hashing.hmacSha1(SHA1_KEY))
.put("HmacSHA256", SHA256_KEY, Hashing.hmacSha256(SHA256_KEY))
.put("HmacSHA512", SHA512_KEY, Hashing.hmacSha512(SHA512_KEY))
.build();
.buildOrThrow();

public void testNulls() {
NullPointerTester tester =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void testCopy_toWriter_fromReadable() throws IOException {
* is permanently reduced, but with certain Reader implementations it could also cause the buffer
* size to reach 0, causing an infinite loop.
*/
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
public void testCopyWithReaderThatDoesNotFillBuffer() throws IOException {
// need a long enough string for the buffer to hit 0 remaining before the copy completes
String string = Strings.repeat("0123456789", 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ public final class InternetDomainNameTest extends TestCase {
private static final String DELTA = "\u0394";

/** A domain part which is valid under lenient validation, but invalid under strict validation. */
@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
static final String LOTS_OF_DELTAS = Strings.repeat(DELTA, 62);

@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
private static final String ALMOST_TOO_MANY_LEVELS = Strings.repeat("a.", 127);

@SuppressWarnings("InlineMeInliner") // String.repeat unavailable under Java 8
private static final String ALMOST_TOO_LONG = Strings.repeat("aaaaa.", 40) + "1234567890.c";

private static final ImmutableSet<String> VALID_NAME =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void testFalseFirst() {
assertThat(Booleans.falseFirst().compare(true, false)).isGreaterThan(0);
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (boolean x : VALUES) {
for (boolean y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private void assertCastFails(long value) {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (char x : VALUES) {
for (char y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void testIsFinite() {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (double x : VALUES) {
for (double y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public void testIsFinite() {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (float x : VALUES) {
for (float y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ private static void assertCastFails(long value) {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (int x : VALUES) {
for (int y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void testHashCode() {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (long x : VALUES) {
for (long y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private static void assertCastFails(long value) {
}
}

// We need to test that our method behaves like the JDK method.
@SuppressWarnings("InlineMeInliner")
public void testCompare() {
for (short x : VALUES) {
for (short y : VALUES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testToLong() {
public void testCompare() {
for (long a : UNSIGNED_INTS) {
for (long b : UNSIGNED_INTS) {
int cmpAsLongs = Longs.compare(a, b);
int cmpAsLongs = Long.compare(a, b);
int cmpAsUInt = UnsignedInts.compare((int) a, (int) b);
assertThat(Integer.signum(cmpAsUInt)).isEqualTo(Integer.signum(cmpAsLongs));
}
Expand Down
Loading

0 comments on commit a3e17c2

Please sign in to comment.