@@ -1100,29 +1100,38 @@ public void visitSkip(JCSkip tree) {
1100
1100
}
1101
1101
1102
1102
public void visitBlock (JCBlock tree ) {
1103
+ /* this method is heavily invoked, as expected, for deeply nested blocks, if blocks doesn't happen to have
1104
+ * patterns there will be an unnecessary tax on memory consumption every time this method is executed, for this
1105
+ * reason we have created helper methods and here at a higher level we just discriminate depending on the
1106
+ * presence, or not, of patterns in a given block
1107
+ */
1103
1108
if (tree .patternMatchingCatch != null ) {
1104
- Set <JCMethodInvocation > prevInvocationsWithPatternMatchingCatch = invocationsWithPatternMatchingCatch ;
1105
- ListBuffer <int []> prevRanges = patternMatchingInvocationRanges ;
1106
- State startState = code .state .dup ();
1107
- try {
1108
- invocationsWithPatternMatchingCatch = tree .patternMatchingCatch .calls2Handle ();
1109
- patternMatchingInvocationRanges = new ListBuffer <>();
1110
- doVisitBlock (tree );
1111
- } finally {
1112
- Chain skipCatch = code .branch (goto_ );
1113
- JCCatch handler = tree .patternMatchingCatch .handler ();
1114
- code .entryPoint (startState , handler .param .sym .type );
1115
- genPatternMatchingCatch (handler , env , patternMatchingInvocationRanges .toList ());
1116
- code .resolve (skipCatch );
1117
- invocationsWithPatternMatchingCatch = prevInvocationsWithPatternMatchingCatch ;
1118
- patternMatchingInvocationRanges = prevRanges ;
1119
- }
1109
+ visitBlockWithPatterns (tree );
1120
1110
} else {
1121
- doVisitBlock (tree );
1111
+ internalVisitBlock (tree );
1112
+ }
1113
+ }
1114
+
1115
+ private void visitBlockWithPatterns (JCBlock tree ) {
1116
+ Set <JCMethodInvocation > prevInvocationsWithPatternMatchingCatch = invocationsWithPatternMatchingCatch ;
1117
+ ListBuffer <int []> prevRanges = patternMatchingInvocationRanges ;
1118
+ State startState = code .state .dup ();
1119
+ try {
1120
+ invocationsWithPatternMatchingCatch = tree .patternMatchingCatch .calls2Handle ();
1121
+ patternMatchingInvocationRanges = new ListBuffer <>();
1122
+ internalVisitBlock (tree );
1123
+ } finally {
1124
+ Chain skipCatch = code .branch (goto_ );
1125
+ JCCatch handler = tree .patternMatchingCatch .handler ();
1126
+ code .entryPoint (startState , handler .param .sym .type );
1127
+ genPatternMatchingCatch (handler , env , patternMatchingInvocationRanges .toList ());
1128
+ code .resolve (skipCatch );
1129
+ invocationsWithPatternMatchingCatch = prevInvocationsWithPatternMatchingCatch ;
1130
+ patternMatchingInvocationRanges = prevRanges ;
1122
1131
}
1123
1132
}
1124
1133
1125
- private void doVisitBlock (JCBlock tree ) {
1134
+ private void internalVisitBlock (JCBlock tree ) {
1126
1135
int limit = code .nextreg ;
1127
1136
Env <GenContext > localEnv = env .dup (tree , new GenContext ());
1128
1137
genStats (tree .stats , localEnv );
0 commit comments