diff options
author | Thomas Wolf | 2020-05-14 14:09:57 +0000 |
---|---|---|
committer | Thomas Wolf | 2020-05-15 09:03:43 +0000 |
commit | 24a28bdaa03e9bb28cb3663e17241c50c4abe1e0 (patch) | |
tree | 9d94b160d90f603b2da9f313b2597a0c907af518 | |
parent | cc5d94f2bf9753fc61c17042238f359e5a09d3bc (diff) | |
download | egit-24a28bdaa03e9bb28cb3663e17241c50c4abe1e0.tar.gz egit-24a28bdaa03e9bb28cb3663e17241c50c4abe1e0.tar.xz egit-24a28bdaa03e9bb28cb3663e17241c50c4abe1e0.zip |
StagingView: speed up updating staged/unstaged viewers
Updating the selection used contains() on the values of a map. That
may be inefficient if many elements are removed. The values are either
StagingEntry or StagingFolderEntry objects, and we know that no two
of them can compare equal(), so use a LinkedHashSet instead.
Moreover, if all paths were removed, avoid any viewer state restoration
at all.
Bug: 563167
Change-Id: I5c07481972625f625dd4ae34ee85330e0118648e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java index 4a8691cb06..32e8c75fca 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java @@ -2328,25 +2328,30 @@ public class StagingView extends ViewPart additionalPaths); } - // Update the selection. - StagingViewerUpdate stagingViewerUpdate = updateSelection( - stagingViewer, contentProvider, oldPaths, - buildElementMap(stagingViewer, contentProvider, - comparator)); - - // If something has been removed, the element before the removed - // item has been selected, in which case we want to preserve the - // scroll state as much as possible, keeping the selection in - // view. If something has been added, those added things have - // been selected and revealed, so we don't want to preserve the - // top but rather leave the revealed selection alone. If nothing - // has changed, we want to preserve the top, regardless of where - // the current unmodified selection might be, which is what's - // done by default anyway. - if (stagingViewerUpdate == StagingViewerUpdate.REMOVED) { - keepSelectionVisible = true; - } else if (stagingViewerUpdate == StagingViewerUpdate.ADDED) { + Map<String, Object> newPaths = buildElementMap(stagingViewer, + contentProvider, comparator); + if (newPaths.isEmpty()) { preserveTop = false; + } else { + // Update the selection. + StagingViewerUpdate stagingViewerUpdate = updateSelection( + stagingViewer, contentProvider, oldPaths, newPaths); + + // If something has been removed, the element before the + // removed item has been selected, in which case we want to + // preserve the scroll state as much as possible, keeping + // the selection in view. If something has been added, those + // added things have been selected and revealed, so we don't + // want to preserve the top but rather leave the revealed + // selection alone. If nothing has changed, we want to + // preserve the top, regardless of where the current + // unmodified selection might be, which is what's done by + // default anyway. + if (stagingViewerUpdate == StagingViewerUpdate.REMOVED) { + keepSelectionVisible = true; + } else if (stagingViewerUpdate == StagingViewerUpdate.ADDED) { + preserveTop = false; + } } } else { // The update is completely different so don't do any of the @@ -2540,7 +2545,8 @@ public class StagingView extends ViewPart // element in the viewer failing those. The general idea is that // it's really annoying to have the viewer scroll to the top // element whenever you drag something out of a staging viewer. - Collection<Object> removedElements = removedPaths.values(); + Collection<Object> removedElements = new LinkedHashSet<>( + removedPaths.values()); Object firstRemovedElement = removedElements.iterator() .next(); Object parent = contentProvider.getParent(firstRemovedElement); |