@@ -1074,29 +1074,38 @@ public void visitSkip(JCSkip tree) {
1074
1074
}
1075
1075
1076
1076
public void visitBlock (JCBlock tree ) {
1077
+ /* this method is heavily invoked, as expected, for deeply nested blocks, if blocks doesn't happen to have
1078
+ * patterns there will be an unnecessary tax on memory consumption every time this method is executed, for this
1079
+ * reason we have created helper methods and here at a higher level we just discriminate depending on the
1080
+ * presence, or not, of patterns in a given block
1081
+ */
1077
1082
if (tree .patternMatchingCatch != null ) {
1078
- Set <JCMethodInvocation > prevInvocationsWithPatternMatchingCatch = invocationsWithPatternMatchingCatch ;
1079
- ListBuffer <int []> prevRanges = patternMatchingInvocationRanges ;
1080
- State startState = code .state .dup ();
1081
- try {
1082
- invocationsWithPatternMatchingCatch = tree .patternMatchingCatch .calls2Handle ();
1083
- patternMatchingInvocationRanges = new ListBuffer <>();
1084
- doVisitBlock (tree );
1085
- } finally {
1086
- Chain skipCatch = code .branch (goto_ );
1087
- JCCatch handler = tree .patternMatchingCatch .handler ();
1088
- code .entryPoint (startState , handler .param .sym .type );
1089
- genPatternMatchingCatch (handler , env , patternMatchingInvocationRanges .toList ());
1090
- code .resolve (skipCatch );
1091
- invocationsWithPatternMatchingCatch = prevInvocationsWithPatternMatchingCatch ;
1092
- patternMatchingInvocationRanges = prevRanges ;
1093
- }
1083
+ visitBlockWithPatterns (tree );
1094
1084
} else {
1095
- doVisitBlock (tree );
1085
+ internalVisitBlock (tree );
1086
+ }
1087
+ }
1088
+
1089
+ private void visitBlockWithPatterns (JCBlock tree ) {
1090
+ Set <JCMethodInvocation > prevInvocationsWithPatternMatchingCatch = invocationsWithPatternMatchingCatch ;
1091
+ ListBuffer <int []> prevRanges = patternMatchingInvocationRanges ;
1092
+ State startState = code .state .dup ();
1093
+ try {
1094
+ invocationsWithPatternMatchingCatch = tree .patternMatchingCatch .calls2Handle ();
1095
+ patternMatchingInvocationRanges = new ListBuffer <>();
1096
+ internalVisitBlock (tree );
1097
+ } finally {
1098
+ Chain skipCatch = code .branch (goto_ );
1099
+ JCCatch handler = tree .patternMatchingCatch .handler ();
1100
+ code .entryPoint (startState , handler .param .sym .type );
1101
+ genPatternMatchingCatch (handler , env , patternMatchingInvocationRanges .toList ());
1102
+ code .resolve (skipCatch );
1103
+ invocationsWithPatternMatchingCatch = prevInvocationsWithPatternMatchingCatch ;
1104
+ patternMatchingInvocationRanges = prevRanges ;
1096
1105
}
1097
1106
}
1098
1107
1099
- private void doVisitBlock (JCBlock tree ) {
1108
+ private void internalVisitBlock (JCBlock tree ) {
1100
1109
int limit = code .nextreg ;
1101
1110
Env <GenContext > localEnv = env .dup (tree , new GenContext ());
1102
1111
genStats (tree .stats , localEnv );
0 commit comments