17
17
18
18
/**
19
19
* Provides overall insight into the structure of a flow graph... but with limited visibility so we can change implementation.
20
- * Designed to work entirely on the basis of the {@link FlowNode#id } rather than the {@link FlowNode}s themselves.
20
+ * Designed to work entirely on the basis of the {@link FlowNode#getId() } rather than the {@link FlowNode}s themselves.
21
21
*/
22
22
@ SuppressFBWarnings (value = "ES_COMPARING_STRINGS_WITH_EQ" , justification = "Can can use instance identity when comparing to a final constant" )
23
23
@ Restricted (NoExternalUse .class )
@@ -40,10 +40,11 @@ public void clearCache() {
40
40
@ Override
41
41
public void onNewHead (@ Nonnull FlowNode newHead ) {
42
42
if (newHead instanceof BlockEndNode ) {
43
- blockStartToEnd .put (((BlockEndNode )newHead ).getStartNode ().getId (), newHead .getId ());
44
- String overallEnclosing = nearestEnclosingBlock .get (((BlockEndNode ) newHead ).getStartNode ().getId ());
45
- if (overallEnclosing != null ) {
46
- nearestEnclosingBlock .put (newHead .getId (), overallEnclosing );
43
+ String startNodeId = ((BlockEndNode )newHead ).getStartNode ().getId ();
44
+ blockStartToEnd .put (startNodeId , newHead .getId ());
45
+ String enclosingId = nearestEnclosingBlock .get (startNodeId );
46
+ if (enclosingId != null ) {
47
+ nearestEnclosingBlock .put (newHead .getId (), enclosingId );
47
48
}
48
49
} else {
49
50
if (newHead instanceof BlockStartNode ) {
@@ -168,11 +169,9 @@ public BlockEndNode getEndNode(@Nonnull final BlockStartNode startNode) {
168
169
throw new RuntimeException (ioe );
169
170
}
170
171
} else {
171
- BlockEndNode node = bruteForceScanForEnd (startNode );
172
- if (node != null ) {
173
- blockStartToEnd .put (startNode .getId (), node .getId ());
174
- }
175
- return node ;
172
+ // returns the end node or null
173
+ // if this returns end node, it also adds start and end to blockStartToEnd
174
+ return bruteForceScanForEnd (startNode );
176
175
}
177
176
}
178
177
@@ -192,12 +191,8 @@ public BlockStartNode findEnclosingBlockStart(@Nonnull FlowNode node) {
192
191
}
193
192
}
194
193
195
- BlockStartNode enclosing = bruteForceScanForEnclosingBlock (node );
196
- if (enclosing != null ) {
197
- nearestEnclosingBlock .put (node .getId (), enclosing .getId ());
198
- return enclosing ;
199
- }
200
- return null ;
194
+ // when scan completes, enclosing is in the cache if it exists
195
+ return bruteForceScanForEnclosingBlock (node );
201
196
}
202
197
203
198
@ Override
0 commit comments