From 42a4000b5aac3018f949da723db90ed2f505aef4 Mon Sep 17 00:00:00 2001 From: Dirk Fauth Date: Wed, 23 Apr 2025 16:50:01 +0200 Subject: [PATCH] Issue #149 - Performance optimizations Signed-off-by: Dirk Fauth --- .../DefaultGlazedListsFilterStrategy.java | 17 +++++++++++------ .../glazedlists/groupBy/GroupByDataLayer.java | 17 +++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/DefaultGlazedListsFilterStrategy.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/DefaultGlazedListsFilterStrategy.java index e1132016..1d3c9929 100644 --- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/DefaultGlazedListsFilterStrategy.java +++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/DefaultGlazedListsFilterStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2024 Original authors and others. + * Copyright (c) 2012, 2025 Original authors and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -268,7 +268,13 @@ public void applyFilter(Map filterIndexToObjectMap) { this.matcherEditor.getMatcherEditors().iterator(); while (existingMatcherEditors.hasNext()) { final MatcherEditor existingMatcherEditor = existingMatcherEditors.next(); - if (!containsMatcherEditor(matcherEditors, existingMatcherEditor)) { + if (existingMatcherEditor instanceof DefaultGlazedListsFilterStrategy.ColumnSetMatcherEditor + || !containsMatcherEditor(matcherEditors, existingMatcherEditor)) { + // always remove an existing + // ColumnSetMatcherEditor as a new one will be + // added if necessary + // done this way to avoid equals() checks based + // on the filter values existingMatcherEditors.remove(); changed = true; } @@ -285,10 +291,9 @@ public void applyFilter(Map filterIndexToObjectMap) { // If there was no change to the MatcherEditors but // applyFilter() was called, probably the re-evaluation - // of the - // filter was requested. To trigger the re-evaluation we - // need to - // add a MatcherEditor that matches all. + // of the filter was requested. To trigger the + // re-evaluation we need to add a MatcherEditor that + // matches all. if (!changed) { this.matcherEditor.getMatcherEditors().add(this.matchAll); this.matcherEditor.getMatcherEditors().remove(this.matchAll); diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java index 90a6339c..d04d220d 100644 --- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java +++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/groupBy/GroupByDataLayer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2024 Original authors and others. + * Copyright (c) 2012, 2025 Original authors and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -30,6 +30,7 @@ import java.util.Observer; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand; import org.eclipse.nebula.widgets.nattable.command.ILayerCommand; @@ -62,7 +63,6 @@ import org.eclipse.swt.widgets.Display; import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.FilterList; import ca.odell.glazedlists.GlazedLists; import ca.odell.glazedlists.TreeList; import ca.odell.glazedlists.TreeList.ExpansionModel; @@ -626,9 +626,9 @@ protected void updateTree() { * caches */ if (GroupByDataLayer.this.groupByExpansionModel != null) { - FilterList groupByObjects = new FilterList<>( - GroupByDataLayer.this.treeList, - GroupByDataLayer.this.groupByMatcher); + List groupByObjects = this.treeList.stream() + .filter(t -> this.groupByMatcher.matches(t)) + .collect(Collectors.toList()); GroupByDataLayer.this.groupByExpansionModel.cleanupCollapsed(groupByObjects); } }); @@ -1012,11 +1012,12 @@ public void cleanupCollapsed(Collection groupByObjects) { */ public List getItemsInGroup(GroupByObject group) { return this.itemsByGroup.computeIfAbsent(group, g -> { - this.eventList.getReadWriteLock().readLock().lock(); try { - FilterList filterList = new FilterList<>(this.eventList, getGroupDescriptorMatcher(g, this.columnAccessor)); - return new ArrayList<>(filterList); + Matcher matcher = getGroupDescriptorMatcher(group, this.columnAccessor); + return this.eventList.stream() + .filter(t -> matcher.matches(t)) + .collect(Collectors.toList()); } finally { this.eventList.getReadWriteLock().readLock().unlock(); }