Skip to content

Commit

Permalink
Don't call toString unless actually needed
Browse files Browse the repository at this point in the history
For each of these assertions, if the check succeeds, then no diagnostic
message will be formed and there's no need to call `toString`.
  • Loading branch information
liblit committed Oct 31, 2023
1 parent 6b4aff9 commit d7b4089
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testSimpleLexical()
.equals(rv.toString())
|| "[Node: <Code body of function Ltests/simple-lexical.js/outer> Context: Everywhere,z]"
.equals(rv.toString()),
rv.toString());
rv::toString);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void checkAssertions(ClassHierarchy cha, TranslatorAssertions assertions)
assertEquals(
"super of " + cls.getName() + " is " + cls.getSuperclass().getName(),
supers.get(cls.getName().toString()),
cls.getSuperclass().getName().toString());
() -> cls.getSuperclass().getName().toString());
}

for (Object name2 : cls.getDeclaredInstanceFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testMissingSuper() throws IOException, ClassHierarchyException {
assertNotNull(klass, "expected class MissingSuper to load");
IAnalysisCacheView cache = new AnalysisCacheImpl();
Collection<? extends IMethod> declaredMethods = klass.getDeclaredMethods();
assertEquals(2, declaredMethods.size(), declaredMethods.toString());
assertEquals(2, declaredMethods.size(), declaredMethods::toString);
for (IMethod m : declaredMethods) {
// should succeed
cache.getIR(m);
Expand Down
54 changes: 27 additions & 27 deletions core/src/test/java/com/ibm/wala/core/tests/slicer/SlicerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testSlice2()
Collection<Statement> slice = computeBackwardSlice;
SlicerUtil.dumpSlice(slice);

assertEquals(9, SlicerUtil.countNormals(slice), slice.toString());
assertEquals(9, SlicerUtil.countNormals(slice), slice::toString);
}

@Test
Expand All @@ -211,7 +211,7 @@ public void testSlice3()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice::toString);
}

@Test
Expand All @@ -238,7 +238,7 @@ public void testSlice4()
Slicer.computeForwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(4, slice.size(), slice.toString());
assertEquals(4, slice.size(), slice::toString);
}

@Test
Expand All @@ -265,7 +265,7 @@ public void testSlice5()
Slicer.computeForwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(7, slice.size(), slice.toString());
assertEquals(7, slice.size(), slice::toString);
}

/** test unreproduced bug reported on mailing list by Sameer Madan, 7/3/2007 */
Expand Down Expand Up @@ -329,7 +329,7 @@ public void testSlice8()
slice =
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
assertEquals(4, slice.size(), slice.toString());
assertEquals(4, slice.size(), slice::toString);
}

@Test
Expand Down Expand Up @@ -386,7 +386,7 @@ public void testTestCD1()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.NONE, ControlDependenceOptions.FULL);
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countConditionals(slice), slice.toString());
assertEquals(2, SlicerUtil.countConditionals(slice), slice::toString);
}

@Test
Expand All @@ -413,7 +413,7 @@ public void testTestCD2()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.NONE, ControlDependenceOptions.FULL);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countConditionals(slice), slice.toString());
assertEquals(1, SlicerUtil.countConditionals(slice), slice::toString);
}

@Test
Expand All @@ -440,7 +440,7 @@ public void testTestCD3()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.NONE, ControlDependenceOptions.FULL);
SlicerUtil.dumpSlice(slice);
assertEquals(0, SlicerUtil.countConditionals(slice), slice.toString());
assertEquals(0, SlicerUtil.countConditionals(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -475,7 +475,7 @@ public void testTestCD4()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countConditionals(slice), slice.toString());
assertEquals(1, SlicerUtil.countConditionals(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -573,7 +573,7 @@ public void testTestCD6()
DataDependenceOptions.NONE,
ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countInvokes(slice), slice.toString());
assertEquals(2, SlicerUtil.countInvokes(slice), slice::toString);
}

@Test
Expand All @@ -600,7 +600,7 @@ public void testTestId()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice::toString);
}

@Test
Expand Down Expand Up @@ -628,8 +628,8 @@ public void testTestArrays()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countAloads(slice), slice.toString());
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(1, SlicerUtil.countAloads(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -657,8 +657,8 @@ public void testTestFields()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countPutfields(slice), slice.toString());
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(1, SlicerUtil.countPutfields(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -701,8 +701,8 @@ public void testThin1()
ControlDependenceOptions.NONE);
slice = computeBackwardSlice;
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countPutfields(slice), slice.toString());
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(1, SlicerUtil.countPutfields(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -730,9 +730,9 @@ public void testTestGlobal()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(2, SlicerUtil.countPutstatics(slice), slice.toString());
assertEquals(2, SlicerUtil.countGetstatics(slice), slice.toString());
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(2, SlicerUtil.countPutstatics(slice), slice::toString);
assertEquals(2, SlicerUtil.countGetstatics(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -760,7 +760,7 @@ public void testTestMultiTarget()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(2, SlicerUtil.countAllocations(slice, false), slice::toString);
}

@Test
Expand Down Expand Up @@ -789,8 +789,8 @@ public void testTestRecursion()
Slicer.computeBackwardSlice(
s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(3, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(2, SlicerUtil.countPutfields(slice), slice.toString());
assertEquals(3, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(2, SlicerUtil.countPutfields(slice), slice::toString);
}

@Test
Expand Down Expand Up @@ -821,8 +821,8 @@ public void testPrimGetterSetter()
Slicer.computeBackwardSlice(
s, pcg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
SlicerUtil.dumpSlice(slice);
assertEquals(0, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countPutfields(slice), slice.toString());
assertEquals(0, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(1, SlicerUtil.countPutfields(slice), slice::toString);
}

/**
Expand Down Expand Up @@ -880,8 +880,8 @@ public void testPrimGetterSetter2()
Slicer.computeBackwardSlice(
s, pcg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
SlicerUtil.dumpSlice(slice);
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice.toString());
assertEquals(1, SlicerUtil.countPutfields(slice), slice.toString());
assertEquals(1, SlicerUtil.countAllocations(slice, false), slice::toString);
assertEquals(1, SlicerUtil.countPutfields(slice), slice::toString);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected void check(CallGraph staticCG, EdgesTest test, Predicate<MethodReferen
if (!filter.test(callerRef)) {
continue loop;
}
assertEquals(1, nodes.size(), callerRef.toString());
assertEquals(1, nodes.size(), callerRef::toString);
caller = nodes.iterator().next();
}

Expand Down

0 comments on commit d7b4089

Please sign in to comment.