diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-06 16:47:23 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-11-07 16:10:40 +0100 |
commit | 1ce597bb9c13cc9b403da355b48e2188344fed71 (patch) | |
tree | 6d7c33902a26bac47b263fcdd3b358329f4d894a /sonar-graph | |
parent | b52699ac73962feafd13afca60af2fe9e5b66a95 (diff) | |
download | sonarqube-1ce597bb9c13cc9b403da355b48e2188344fed71.tar.gz sonarqube-1ce597bb9c13cc9b403da355b48e2188344fed71.zip |
SONAR-5672 Decrease memory comsumption when working on very big DSM with empty cells
Diffstat (limited to 'sonar-graph')
-rw-r--r-- | sonar-graph/src/main/java/org/sonar/graph/Dsm.java | 23 | ||||
-rw-r--r-- | sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java | 9 |
2 files changed, 23 insertions, 9 deletions
diff --git a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java b/sonar-graph/src/main/java/org/sonar/graph/Dsm.java index 972b44bd1e2..fc9f386fff2 100644 --- a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java +++ b/sonar-graph/src/main/java/org/sonar/graph/Dsm.java @@ -19,6 +19,8 @@ */ package org.sonar.graph; +import javax.annotation.CheckForNull; + import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -53,9 +55,10 @@ public class Dsm<V> { V to = vertices[y]; Edge<V> edge = graph.getEdge(from, to); - boolean isFeedbackEdge = edge != null && feedbackEdges.contains(edge); - DsmCell cell = new DsmCell(edge, isFeedbackEdge); - cells[x][y] = cell; + if (edge != null) { + boolean isFeedbackEdge = feedbackEdges.contains(edge); + cells[x][y] = new DsmCell(edge, isFeedbackEdge); + } } } } @@ -129,7 +132,7 @@ public class Dsm<V> { int incomingEdges = 0; for (int x = from; x <= to; x++) { DsmCell cell = cells[x][y]; - if (cell.getWeight() != 0 && !cell.isFeedbackEdge()) { + if (cell != null && cell.getWeight() != 0 && !cell.isFeedbackEdge()) { incomingEdges++; } } @@ -140,14 +143,24 @@ public class Dsm<V> { int outgoingEdges = 0; for (int y = from; y <= to; y++) { DsmCell cell = cells[x][y]; - if (cell.getWeight() != 0 && !cell.isFeedbackEdge()) { + if (cell != null && cell.getWeight() != 0 && !cell.isFeedbackEdge()) { outgoingEdges++; } } return outgoingEdges; } + /** + * @deprecated since 5.0 use {@link #cell(int, int)} + */ + @Deprecated public DsmCell getCell(int x, int y) { + DsmCell cell = cells[x][y]; + return cell != null ? cell : new DsmCell(null, false); + } + + @CheckForNull + public DsmCell cell(int x, int y) { return cells[x][y]; } diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java b/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java index 0676aed7ecb..5cdbd694829 100644 --- a/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java +++ b/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java @@ -46,7 +46,7 @@ public final class DsmPrinter { printRow(y); } writer.flush(); - + } catch (IOException e) { throw new RuntimeException("Unable to print the desired DSM.", e); // NOSONAR } @@ -76,12 +76,13 @@ public final class DsmPrinter { } private void printCell(int y, int x) throws IOException { - if (dsm.getCell(x, y).getWeight() == 0) { + DsmCell cell = dsm.cell(x, y); + if (cell == null || cell.getWeight() == 0) { writer.append(" "); } else { - writer.append("").append(String.valueOf(dsm.getCell(x, y).getWeight())); + writer.append("").append(String.valueOf(cell.getWeight())); } - if (dsm.getCell(x, y).isFeedbackEdge()) { + if (cell != null && cell.isFeedbackEdge()) { writer.append(FEEDBACK_EDGE_FLAG); } else { writer.append(' '); |