mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-18 10:13:38 +00:00
List box memory usage improvements [stage]
This commit is contained in:
parent
516cfced4a
commit
e4b01ccf0b
2 changed files with 32 additions and 13 deletions
|
@ -26,6 +26,7 @@ import javafx.scene.layout.VBox;
|
|||
import lombok.Setter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
||||
|
@ -60,10 +61,26 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
|||
vbox.setFocusTraversable(false);
|
||||
var scroll = new ScrollPane(vbox);
|
||||
|
||||
refresh(scroll, vbox, shown, all, cache, false, false);
|
||||
|
||||
shown.addListener((ListChangeListener<? super T>) (c) -> {
|
||||
refresh(scroll, vbox, c.getList(), all, cache, true, true);
|
||||
var l = (ListChangeListener<? super T>) (c) -> {
|
||||
Platform.runLater(() -> {
|
||||
refresh(scroll, vbox, c.getList(), all, cache, true);
|
||||
});
|
||||
};
|
||||
scroll.sceneProperty().subscribe(scene -> {
|
||||
if (scene != null) {
|
||||
shown.addListener(l);
|
||||
} else {
|
||||
shown.removeListener(l);
|
||||
}
|
||||
});
|
||||
scroll.sceneProperty().addListener((observableValue, oldScene, newScene) -> {
|
||||
// Apply changes made since init and scene assign
|
||||
if (oldScene == null && newScene != null) {
|
||||
refresh(scroll, vbox, shown, all, cache, true);
|
||||
}
|
||||
if (oldScene != null && newScene == null) {
|
||||
cache.clear();
|
||||
}
|
||||
});
|
||||
|
||||
if (scrollBar) {
|
||||
|
@ -228,7 +245,6 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
|||
List<? extends T> shown,
|
||||
List<? extends T> all,
|
||||
Map<T, Region> cache,
|
||||
boolean asynchronous,
|
||||
boolean refreshVisibilities) {
|
||||
Runnable update = () -> {
|
||||
synchronized (cache) {
|
||||
|
@ -237,7 +253,9 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
|||
set.addAll(shown);
|
||||
set.addAll(all);
|
||||
// Clear cache of unused values
|
||||
cache.keySet().removeIf(t -> !set.contains(t));
|
||||
cache.keySet().removeIf(t -> {
|
||||
return !set.contains(t);
|
||||
});
|
||||
}
|
||||
|
||||
// Create copy to reduce chances of concurrent modification
|
||||
|
@ -245,6 +263,12 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
|||
var newShown = shownCopy.stream()
|
||||
.map(v -> {
|
||||
if (!cache.containsKey(v)) {
|
||||
// System.out.println("cache miss: " + v);
|
||||
if (scroll.getScene() == null) {
|
||||
// System.out.println("Ignored " + v);
|
||||
return null;
|
||||
}
|
||||
|
||||
var comp = compFunction.apply(v);
|
||||
if (comp != null) {
|
||||
var r = comp.createRegion();
|
||||
|
@ -280,11 +304,6 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
|
|||
updateVisibilities(scroll, listView);
|
||||
}
|
||||
};
|
||||
|
||||
if (asynchronous) {
|
||||
Platform.runLater(update);
|
||||
} else {
|
||||
PlatformThread.runLaterIfNeeded(update);
|
||||
}
|
||||
update.run();
|
||||
}
|
||||
}
|
||||
|
|
2
version
2
version
|
@ -1 +1 @@
|
|||
15.7-2
|
||||
15.7-3
|
||||
|
|
Loading…
Add table
Reference in a new issue