changeset: 164450:569a84590c9b tag: tip user: Vladimir Voskresensky date: Tue Mar 23 14:05:03 2010 +0300 summary: fixing #181684 - NB platform consumes a lot of memory on big projects. diff --git a/openide.filesystems/src/org/openide/filesystems/FileObject.java b/openide.filesystems/src/org/openide/filesystems/FileObject.java --- a/openide.filesystems/src/org/openide/filesystems/FileObject.java +++ b/openide.filesystems/src/org/openide/filesystems/FileObject.java @@ -172,7 +172,7 @@ public String toString() { String cname = getClass().getName(); String cnameShort = cname.substring(cname.lastIndexOf('.') + 1); - + try { return cnameShort + '@' + Integer.toHexString(System.identityHashCode(this)) + '[' + (isRoot() ? "root of " + getFileSystem() : getPath()) + ']'; // NOI18N } catch (FileStateInvalidException x) { @@ -612,7 +612,7 @@ /** Reads the full content of the file object and returns it as string. * This is similar to calling {@link #asText(java.lang.String)} with * default system encoding. - * + * * @return string representing the content of the file * @exception IOException in case the content cannot be fully read * @since 7.21 @@ -641,7 +641,7 @@ public List asLines() throws IOException { return asLines(Charset.defaultCharset().name()); } - + /** Reads the full content of the file line by line. Typical usage is * in for loops: *
@@ -712,7 +712,7 @@
         }
     }
 
-    
+
     /** Lock this file.
     * @return lock that can be used to perform various modifications on the file
     * @throws FileAlreadyLockedException if the file is already locked
@@ -830,7 +830,7 @@
 
         FileObject myObj = this;
         StringTokenizer st = new StringTokenizer(relativePath, "/");
-        
+
         if(relativePath.startsWith("//")) {
             // if it is UNC absolute path, start with //ComputerName/sharedFolder
             myObj = myObj.getFileObject("//"+st.nextToken()+"/"+st.nextToken(), null);
@@ -879,7 +879,7 @@
      * @see FileUtil#createData
      */
     public FileObject createData(String name) throws IOException {
-        return createData(name, ""); // NOI18N        
+        return createData(name, ""); // NOI18N
     }
 
     /** Test whether this file can be written to or not.
@@ -1023,13 +1023,13 @@
 
     interface PriorityFileChangeListener extends FileChangeListener {}
 
-    private class ED extends FileSystem.EventDispatcher {
+    private static class ED extends FileSystem.EventDispatcher {
         private FCLSupport.Op op;
         private Enumeration en;
         final private List fsList;
         final private List repList;
-        
-        
+
+
         private FileEvent fe;
 
         public ED(FCLSupport.Op op, Enumeration en, FileEvent fe) {
@@ -1044,11 +1044,16 @@
             }
             ListenerList fsll = (fs != null) ? fs.getFCLSupport().listeners : null;
             ListenerList repll = (fs != null && fs.getRepository() != null) ? fs.getRepository().getFCLSupport().listeners : null;
-            fsList = (fsll != null) ? new ArrayList(fsll.getAllListeners()) :
-                new ArrayList();
-            repList = (repll != null) ? new ArrayList(repll.getAllListeners()) :
-                new ArrayList();
-            
+            if (fsll != null && fsll.hasListeners()) {
+                fsList = new ArrayList(fsll.getAllListeners());
+            } else {
+                fsList = Collections.emptyList();
+            }
+            if (repll != null && repll.hasListeners()) {
+                repList = new ArrayList(repll.getAllListeners());
+            } else {
+                repList = Collections.emptyList();
+            }
         }
 
         public ED(Enumeration en, FileEvent fe) {
@@ -1063,7 +1068,7 @@
                 this.op = fe.getFile().isFolder() ? FCLSupport.Op.FOLDER_CREATED : FCLSupport.Op.DATA_CREATED;
             }
 
-            LinkedList newEnum = new LinkedList(); // later lazy                
+            LinkedList newEnum = new LinkedList(); // later lazy
 
             while (en.hasMoreElements()) {
                 FileChangeListener fcl = en.nextElement();
@@ -1084,7 +1089,7 @@
              * FileSystem and from Repository mustn`t be forked.
              */
             FileObject fo = fe.getFile();
-            boolean transmit = false;            
+            boolean transmit = false;
             if (fo != null) {
                 switch (op) {
                     case FILE_CHANGED:
@@ -1094,10 +1099,10 @@
                         transmit = !fo.equals(fe.getSource());
                         if (!transmit && fe instanceof Enumeration && !((Enumeration) fe).hasMoreElements()) {
                             transmit = true;
-                        } 
+                        }
                 }
-                
-            }                
+
+            }
 
             if (!en.hasMoreElements() && transmit && !onlyPriority) {
                 FileSystem fs = null;
@@ -1112,14 +1117,14 @@
                 if (fs != null && fsList != null) {
                     for (FileChangeListener fcl : fsList) {
                         FCLSupport.dispatchEvent(fcl, fe, op, postNotify);
-                    }  
+                    }
                 }
 
 
                 if (rep != null && repList != null) {
                     for (FileChangeListener fcl : repList) {
                         FCLSupport.dispatchEvent(fcl, fe, op, postNotify);
-                    }                      
+                    }
                 }
             }
         }