Skip to content

Commit 169cc75

Browse files
authored
Merge pull request github#6840 from aschackmull/java/misc-perf
Java: Fix some performance issues.
2 parents a204b7f + 306388a commit 169cc75

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

java/ql/src/Likely Bugs/Collections/IteratorRemoveMayFail.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ predicate containsSpecialCollection(Expr e, SpecialCollectionCreation origin) {
3030
e = origin
3131
or
3232
exists(Variable v |
33-
containsSpecialCollection(v.getAnAssignedValue(), origin) and
33+
containsSpecialCollection(pragma[only_bind_into](v.getAnAssignedValue()), origin) and
3434
e = v.getAnAccess()
3535
)
3636
or
@@ -52,7 +52,7 @@ predicate iterOfSpecialCollection(Expr e, SpecialCollectionCreation origin) {
5252
)
5353
or
5454
exists(Variable v |
55-
iterOfSpecialCollection(v.getAnAssignedValue(), origin) and
55+
iterOfSpecialCollection(pragma[only_bind_into](v.getAnAssignedValue()), origin) and
5656
e = v.getAnAccess()
5757
)
5858
or

java/ql/src/Likely Bugs/Comparison/StringComparison.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ class StringValue extends Expr {
4141
}
4242
}
4343

44-
predicate variableValuesInterned(Variable v) {
44+
pragma[noinline]
45+
predicate candidateVariable(Variable v) {
4546
v.fromSource() and
46-
// All assignments to variables are interned.
47-
forall(StringValue sv | sv = v.getAnAssignedValue() | sv.isInterned()) and
4847
// For parameters, assume they could be non-interned.
4948
not v instanceof Parameter and
5049
// If the string is modified with `+=`, then the new string is not interned
5150
// even if the components are.
5251
not exists(AssignOp append | append.getDest() = v.getAnAccess())
5352
}
5453

54+
predicate variableValuesInterned(Variable v) {
55+
candidateVariable(v) and
56+
// All assignments to variables are interned.
57+
forall(StringValue sv | sv = v.getAnAssignedValue() | sv.isInterned())
58+
}
59+
5560
from EqualityTest e, StringValue lhs, StringValue rhs
5661
where
5762
e.getLeftOperand() = lhs and

java/ql/src/Performance/InnerClassCouldBeStatic.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import java
1717
* since package-protected fields are not inherited by classes in different
1818
* packages, but it's enough for the purposes of this check.
1919
*/
20+
pragma[nomagic]
2021
predicate inherits(Class c, Field f) {
2122
f = c.getAField()
2223
or

0 commit comments

Comments
 (0)