JDK-6655730 : Improve the performance of the LoadFilesThread class in BasicDirectoryModel
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-01-28
  • Updated: 2011-02-16
  • Resolved: 2009-11-03
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
The LoadFilesThread class in javax.swing.plaf.basic.BasicDirectoryModel could be made more efficient. There are loops that compute the length of the array on each loop as in the following:
 for (int i = 0; i < list.length; i++) {
                        if(filechooser.accept(list[i])) {
                            acceptsList.addElement(list[i]);
                        }
                    }


JUSTIFICATION :
JFileChooser performance is paramount in order to make it fast. Many people have complained that it is slow when loading directories with huge number of files. Implementing the fix will improve on that.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would do the following instead:
 for (int i = 0, size = list.length; i < size; i++) {
                        if(filechooser.accept(list[i])) {
                            acceptsList.addElement(list[i]);
                        }
                    }
That way the list's length is just computed once.