Revision: 7338
Author: [email protected]
Date: Fri Dec 18 10:24:21 2009
Log: When SameParameterValueOptimizer substitutes a value
for a parameter, it now casts the value to the type
of the parameter.  This prevents, for example,
treating an integer as a long.

Review by: scottb

http://code.google.com/p/google-web-toolkit/source/detail?r=7338

Modified:
   
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
   
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java

=======================================
---  
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
         
Fri Dec 18 09:13:44 2009
+++  
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
         
Fri Dec 18 10:24:21 2009
@@ -173,7 +173,6 @@
     * all calls.
     */
    private Map<JParameter, JValueLiteral> parameterValues = new  
IdentityHashMap<JParameter, JValueLiteral>();
-
    private final JProgram program;

    /**
@@ -183,9 +182,11 @@
     * TODO: support polymorphic calls properly.
     */
    private Set<JMethod> rescuedMethods = new HashSet<JMethod>();
+  private final Simplifier simplifier;

    private SameParameterValueOptimizer(JProgram program) {
      this.program = program;
+    simplifier = new Simplifier(program);
    }

    private boolean execImpl(JNode node) {
@@ -200,7 +201,7 @@
        JValueLiteral valueLiteral = parameterValues.get(parameter);
        if (valueLiteral != null) {
          SubstituteParameterVisitor substituteParameterVisitor = new  
SubstituteParameterVisitor(
-            parameter, valueLiteral);
+            parameter, simplifier.cast(parameter.getType(), valueLiteral));
          substituteParameterVisitor.accept(parameter.getEnclosingMethod());
          madeChanges |= substituteParameterVisitor.didChange();
        }
=======================================
---  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
    
Fri Dec 18 09:13:44 2009
+++  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
    
Fri Dec 18 10:24:21 2009
@@ -39,6 +39,12 @@
      assertOptimize("foo", "static int foo(int i) { return i;  
}", "foo(foo(1));").into(
          "public static int foo(int i){", "  return i;", "}");
    }
+
+  public void testNumericCast() throws Exception {
+    assertOptimize("foo", "static void foo(long i) { long j = i; }",
+        "foo(1); foo(1);").into("public static void foo(long i){",
+        "  long j = 1L;", "}");
+  }

    public void testSameParameter() throws Exception {
      assertOptimize("foo", "static void foo(int i) { int j = i; }",

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to