Print the information about "needs" only once per each type
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 30 Oct 2012 22:35:32 +0100
changeset 12915df78d24302
parent 128 8db5cf267d74
child 130 0b7c9b5b8079
Print the information about "needs" only once per each type
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Oct 30 22:22:18 2012 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Oct 30 22:35:32 2012 +0100
     1.3 @@ -967,9 +967,10 @@
     1.4      }
     1.5      
     1.6      private void addReference(String cn) throws IOException {
     1.7 -        out.append(" /* needs ").append(cn).append(" */");
     1.8          if (references != null) {
     1.9 -            references.add(cn);
    1.10 +            if (references.add(cn)) {
    1.11 +                out.append(" /* needs ").append(cn).append(" */");
    1.12 +            }
    1.13          }
    1.14      }
    1.15  
     2.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java	Tue Oct 30 22:22:18 2012 +0100
     2.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java	Tue Oct 30 22:35:32 2012 +0100
     2.3 @@ -23,11 +23,13 @@
     2.4  import java.io.InputStream;
     2.5  import java.io.Writer;
     2.6  import java.net.URL;
     2.7 +import java.util.ArrayList;
     2.8  import java.util.Arrays;
     2.9  import java.util.Collections;
    2.10  import java.util.Enumeration;
    2.11  import java.util.HashMap;
    2.12  import java.util.Iterator;
    2.13 +import java.util.LinkedHashSet;
    2.14  import java.util.LinkedList;
    2.15  import java.util.List;
    2.16  import java.util.Map;
    2.17 @@ -59,8 +61,16 @@
    2.18      }
    2.19      static void compile(ClassLoader l, Appendable out, List<String> names) throws IOException {
    2.20          for (String baseClass : names) {
    2.21 -            Map<String,String> processed = new HashMap<String, String>();
    2.22 -            LinkedList<String> toProcess = new LinkedList<String>();
    2.23 +            final Map<String,String> processed = new HashMap<String, String>();
    2.24 +            LinkedHashSet<String> toProcess = new LinkedHashSet<String>() {
    2.25 +                @Override
    2.26 +                public boolean add(String e) {
    2.27 +                    if (processed.containsKey(e)) {
    2.28 +                        return false;
    2.29 +                    }
    2.30 +                    return super.add(e);
    2.31 +                }
    2.32 +            };
    2.33              toProcess.add(baseClass);
    2.34              for (;;) {
    2.35                  String name = null;
    2.36 @@ -75,25 +85,7 @@
    2.37                  if (name == null) {
    2.38                      break;
    2.39                  }
    2.40 -                if (name.startsWith("java/")
    2.41 -                    && !name.equals("java/lang/Object")
    2.42 -                    && !name.equals("java/lang/Class")
    2.43 -                    && !name.equals("java/lang/Math")
    2.44 -                    && !name.equals("java/lang/Number")
    2.45 -                    && !name.equals("java/lang/NumberFormatException")
    2.46 -                    && !name.equals("java/lang/IllegalArgumentException")
    2.47 -                    && !name.equals("java/lang/Integer")
    2.48 -                    && !name.equals("java/lang/Float")
    2.49 -                    && !name.equals("java/lang/Double")
    2.50 -                    && !name.equals("java/lang/Throwable")
    2.51 -                    && !name.equals("java/lang/Exception")
    2.52 -                    && !name.equals("java/lang/RuntimeException")
    2.53 -                    && !name.equals("java/lang/UnsupportedOperationException")
    2.54 -                    && !name.equals("java/lang/String")
    2.55 -                    && !name.equals("java/lang/String$CaseInsensitiveComparator")
    2.56 -                    && !name.equals("java/lang/StringBuilder")
    2.57 -                    && !name.equals("java/lang/AbstractStringBuilder")
    2.58 -                ) {
    2.59 +                if (name.startsWith("sun/")) {
    2.60                      processed.put(name, "");
    2.61                      continue;
    2.62                  }            
    2.63 @@ -134,10 +126,11 @@
    2.64                      readResource(emul, out);
    2.65                  }
    2.66              }
    2.67 -            
    2.68 -            Collections.reverse(toProcess);
    2.69  
    2.70 -            for (String clazz : toProcess) {
    2.71 +            List<String> toInit = new ArrayList<String>(toProcess);
    2.72 +            Collections.reverse(toInit);
    2.73 +
    2.74 +            for (String clazz : toInit) {
    2.75                  String initCode = processed.remove(clazz);
    2.76                  if (initCode != null) {
    2.77                      out.append(initCode).append("\n");