From 155dec327b975d3b4ce3975be19410eda54214b7 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Wed, 4 Feb 2015 21:59:47 +0100 Subject: [PATCH] Performance improvements --- .../sourcefolder/SourceFolderFilter.java | 18 +++++++++++++----- .../SourceFolderFilterExtension.java | 9 ++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilter.java b/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilter.java index afd77bbe..6053934d 100644 --- a/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilter.java +++ b/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilter.java @@ -23,15 +23,19 @@ public List getAllSourceFolders() { return allSourceFolders; } - public void updateSourceFolders( List allSourceFolders ) { + public boolean updateSourceFolders( List allSourceFolders ) { + if( this.allSourceFolders.equals( allSourceFolders ) ) { + return false; + } this.visibleSourceFolders.retainAll( allSourceFolders ); this.visibleSourceFolders.addAll( addedSourceFolders( allSourceFolders ) ); - this.allSourceFolders = new LinkedList( allSourceFolders ); + this.allSourceFolders = new ArrayList( allSourceFolders ); + return true; } - private LinkedList addedSourceFolders( List newSourceFolders ) { + private List addedSourceFolders( List newSourceFolders ) { List oldSourceFolders = this.allSourceFolders; - LinkedList result = new LinkedList( newSourceFolders ); + List result = new LinkedList( newSourceFolders ); result.removeAll( oldSourceFolders ); return result; } @@ -51,6 +55,10 @@ public String getDescription() { @Override protected boolean select( GraphNode node, Set others ) { + return !isFiltering() || isContainedByVisibleSourceFolder( node ); + } + + private boolean isContainedByVisibleSourceFolder( GraphNode node ) { IJavaElement javaElement = JavaCore.create( node.getFile() ); IJavaElement packageFragmentRoot = javaElement.getAncestor( IJavaElement.PACKAGE_FRAGMENT_ROOT ); IJavaProject javaProject = packageFragmentRoot.getJavaProject(); @@ -63,6 +71,6 @@ protected boolean select( GraphNode node, Set others ) { } public boolean isFiltering() { - return getAllSourceFolders().size() > getVisibleSourceFolders().size(); + return allSourceFolders.size() > visibleSourceFolders.size(); } } diff --git a/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilterExtension.java b/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilterExtension.java index 2a5bacbe..65b4a601 100644 --- a/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilterExtension.java +++ b/org.projectusus.ui.dependencygraph/src/org/projectusus/ui/dependencygraph/sourcefolder/SourceFolderFilterExtension.java @@ -5,6 +5,7 @@ import static org.projectusus.core.statistics.UsusModelProvider.ususModel; import static org.projectusus.ui.dependencygraph.sourcefolder.SourceFolderChangeDetector.detectSourceFolderChange; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -77,9 +78,11 @@ private void recomputeSourceFolders() { IJavaProject[] ususJavaProjects = convertToJavaProjects( ususProjects ); Set allSourceFolders = scanForSourceFolders( ususJavaProjects ); - filter.updateSourceFolders( new LinkedList( allSourceFolders ) ); - action.updateState(); - refreshable.refresh(); + boolean changed = filter.updateSourceFolders( new ArrayList( allSourceFolders ) ); + if( changed ) { + action.updateState(); + refreshable.refresh(); + } } private Set scanForSourceFolders( IJavaProject[] ususJavaProjects ) {