Skip to content

Commit 10bfa39

Browse files
committed
Explicitely use no-arg constructor
- Inadvertly I was using the constructor that received an int as initial capacity, which instantiated massive collections leading to an increase in memory usage.
1 parent 06ba547 commit 10bfa39

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ private void reportMatch(TokenEntry mark1, TokenEntry mark2, int dupes) {
6868
* - BC
6969
* It should be reduced to a single match with 3 marks
7070
*/
71-
if (tokenMatchSets.computeIfAbsent(mark1.getIndex(), HashSet::new).contains(mark2.getIndex())) {
71+
if (tokenMatchSets.computeIfAbsent(mark1.getIndex(), (i) -> new HashSet<>()).contains(mark2.getIndex())) {
7272
return;
7373
}
7474

7575
// This may not be a "new match", but actually a sub-match of a larger one.
7676
// always rely on the lowest mark index, as that's the order in which process them
7777
final int lowestKey = tokenMatchSets.get(mark1.getIndex()).stream().reduce(mark1.getIndex(), Math::min);
7878

79-
List<Match> matches = matchTree.computeIfAbsent(lowestKey, ArrayList::new);
79+
List<Match> matches = matchTree.computeIfAbsent(lowestKey, (i) -> new ArrayList<>());
8080
Iterator<Match> matchIterator = matches.iterator();
8181
while (matchIterator.hasNext()) {
8282
Match m = matchIterator.next();
@@ -116,8 +116,8 @@ private void reportMatch(TokenEntry mark1, TokenEntry mark2, int dupes) {
116116
}
117117

118118
private void registerTokenMatch(TokenEntry mark1, TokenEntry mark2) {
119-
tokenMatchSets.computeIfAbsent(mark1.getIndex(), HashSet::new).add(mark2.getIndex());
120-
tokenMatchSets.computeIfAbsent(mark2.getIndex(), HashSet::new).add(mark1.getIndex());
119+
tokenMatchSets.computeIfAbsent(mark1.getIndex(), (i) -> new HashSet<>()).add(mark2.getIndex());
120+
tokenMatchSets.computeIfAbsent(mark2.getIndex(), (i) -> new HashSet<>()).add(mark1.getIndex());
121121
}
122122

123123
List<Match> getMatches() {

0 commit comments

Comments
 (0)