changeset 53402:161f50ac07ea intrinsics-project

Restrict folding to specific methods
author jlaskey
date Mon, 12 Nov 2018 11:35:33 -0400
parents 0f433c4c2aee
children 30b442c98ce4
files src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/StringProcessorFactory.java
diffstat 1 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/StringProcessorFactory.java	Thu Nov 08 22:08:39 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/StringProcessorFactory.java	Mon Nov 12 11:35:33 2018 -0400
@@ -99,18 +99,27 @@
                         break;
                 }
 
-                // Fold when all arguments are constant
-                if (Intrinsics.isAllConstants(constantArgs)) {
-                    try {
-                        ConstantDesc value =
-                                Intrinsics.invoke(String.class, methodName, isStatic,
-                                        methodType.returnType(), argClassDescs, constantArgs);
-                        return new Result.Ldc(value);
-                    } catch (Exception ex) {
-                        return new Result.None();
-                    }
+                switch (methodName) {
+                    case "align":
+                    case "indent":
+                    case "length":
+                    case "repeat":
+                    case "strip":
+                    case "stripLeading":
+                    case "stripTrailing":
+                        // Fold when all arguments are constant
+                        if (Intrinsics.isAllConstants(constantArgs)) {
+                            try {
+                                ConstantDesc value =
+                                        Intrinsics.invoke(String.class, methodName, isStatic,
+                                                methodType.returnType(), argClassDescs, constantArgs);
+                                return new Result.Ldc(value);
+                            } catch (Exception ex) {
+                                return new Result.None();
+                            }
+                        }
                 }
-            }
+             }
 
             return new Result.None();
         }