Revision: 7336
Author: [email protected]
Date: Fri Dec 18 09:13:44 2009
Log: Sort and format.

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

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
         
Wed Nov 11 11:58:14 2009
+++  
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
         
Fri Dec 18 09:13:44 2009
@@ -51,11 +51,11 @@
          parameterValues.put(((JParameterRef) x.getLhs()).getParameter(),  
null);
        }
      }
-
+
      @Override
      public void endVisit(JMethodCall x, Context ctx) {
        JMethod method = x.getTarget();
-
+
        if (x.canBePolymorphic() || rescuedMethods.contains(method)) {
          return;
        }
@@ -112,27 +112,27 @@
          rescuedMethods.add(x);
        } else {
          JMethod staticImpl = program.staticImplFor(x);
-        if (staticImpl != null &&
-             
staticImpl.getEnclosingType().getMethods().contains(staticImpl)) {
+        if (staticImpl != null
+            &&  
staticImpl.getEnclosingType().getMethods().contains(staticImpl)) {
            // instance method is still alive.
            rescuedMethods.add(x);
          }
        }
        return true;
      }
-
+
      private boolean equalLiterals(JValueLiteral l1, JValueLiteral l2) {
        Object v1 = l1.getValueObj();
        Object v2 = l2.getValueObj();
-
+
        if (v1 == v2) {
          return true;
        }
-
+
        if (v1 == null || v2 == null) {
          return false;
        }
-
+
        return v1.equals(v2);
      }
    }
@@ -167,23 +167,22 @@
    /**
     * Parameter values.
     *
-   * If doesn't contain a parameter, then its value is unknown.
-   * If contains parameter, and value is null - the parameter's value is  
not the
-   * same across all calls.
-   * If value is not null - the parameter's value is the same across all  
calls.
+   * If doesn't contain a parameter, then its value is unknown. If contains
+   * parameter, and value is null - the parameter's value is not the same  
across
+   * all calls. If value is not null - the parameter's value is the same  
across
+   * all calls.
     */
-  private Map<JParameter, JValueLiteral> parameterValues =
-    new IdentityHashMap<JParameter, JValueLiteral>();
+  private Map<JParameter, JValueLiteral> parameterValues = new  
IdentityHashMap<JParameter, JValueLiteral>();
+
+  private final JProgram program;

    /**
-   * These methods should not be tried to optimized due to their  
polymorphic
+   * These methods should not be tried to optimized due to their  
polymorphic
     * nature.
     *
     * TODO: support polymorphic calls properly.
     */
    private Set<JMethod> rescuedMethods = new HashSet<JMethod>();
-
-  private final JProgram program;

    private SameParameterValueOptimizer(JProgram program) {
      this.program = program;
@@ -200,8 +199,8 @@
        }
        JValueLiteral valueLiteral = parameterValues.get(parameter);
        if (valueLiteral != null) {
-        SubstituteParameterVisitor substituteParameterVisitor =
-          new SubstituteParameterVisitor(parameter, valueLiteral);
+        SubstituteParameterVisitor substituteParameterVisitor = new  
SubstituteParameterVisitor(
+            parameter, valueLiteral);
          substituteParameterVisitor.accept(parameter.getEnclosingMethod());
          madeChanges |= substituteParameterVisitor.didChange();
        }
=======================================
---  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
    
Wed Nov 11 11:58:14 2009
+++  
/trunk/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
    
Fri Dec 18 09:13:44 2009
@@ -10,39 +10,6 @@
   * Test for SameParameterValueOptimizer.
   */
  public class SameParameterValueOptimizerTest extends OptimizerTestBase {
-  public void testSameParameter() throws Exception {
-    assertOptimize("foo", "static void foo(int i) { int j = i; }",
-        "foo(1); foo(1);").into(
-        "public static void foo(int i){",
-        "  int j = 1;",
-        "}");
-  }
-
-  public void testDifferentParameter() throws Exception {
-    assertOptimize("foo", "static void foo(int i) { int j = i; }",
-        "foo(1); foo(2);").into(
-        "public static void foo(int i){",
-        "  int j = i;",
-        "}");
-  }
-
-  public void testNonConstParameter() throws Exception {
-    assertOptimize("foo", "static int foo(int i) { return i; }",
-        "foo(foo(1));").into(
-        "public static int foo(int i){",
-        "  return i;",
-        "}");
-  }
-
-  private OptimizationResult assertOptimize(String methodName,
-      String methodDecl, String codeSnippet) throws  
UnableToCompleteException {
-    addSnippetClassDecl(methodDecl);
-    JProgram program = compileSnippet("void", codeSnippet);
-    SameParameterValueOptimizer.exec(program);
-    JMethod method = findMethod(program, methodName);
-    return new OptimizationResult(method);
-  }
-
    private static class OptimizationResult {
      private final JMethod method;

@@ -50,7 +17,7 @@
        this.method = method;
      }

-    public void into(String...expectedStrings) {
+    public void into(String... expectedStrings) {
        StringBuffer expected = new StringBuffer();
        for (String s : expectedStrings) {
          if (expected.length() != 0) {
@@ -61,4 +28,30 @@
        assertEquals(expected.toString(), method.toSource());
      }
    }
-}
+
+  public void testDifferentParameter() throws Exception {
+    assertOptimize("foo", "static void foo(int i) { int j = i; }",
+        "foo(1); foo(2);").into("public static void foo(int i){",
+        "  int j = i;", "}");
+  }
+
+  public void testNonConstParameter() throws Exception {
+    assertOptimize("foo", "static int foo(int i) { return i;  
}", "foo(foo(1));").into(
+        "public static int foo(int i){", "  return i;", "}");
+  }
+
+  public void testSameParameter() throws Exception {
+    assertOptimize("foo", "static void foo(int i) { int j = i; }",
+        "foo(1); foo(1);").into("public static void foo(int i){",
+        "  int j = 1;", "}");
+  }
+
+  private OptimizationResult assertOptimize(String methodName,
+      String methodDecl, String codeSnippet) throws  
UnableToCompleteException {
+    addSnippetClassDecl(methodDecl);
+    JProgram program = compileSnippet("void", codeSnippet);
+    SameParameterValueOptimizer.exec(program);
+    JMethod method = findMethod(program, methodName);
+    return new OptimizationResult(method);
+  }
+}

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

Reply via email to