Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8197991: Selecting many items in a TableView is very slow #127

Open
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@ public void callObservers(Change<E> c) {
@Override public int indexOf(Object o) {
if (o == null) return -1;

for (int i = 0; i < size(); i++) {
for (int i = 0, max = size(); i < max; i++) {
Object obj = get(i);
if (o.equals(obj)) return i;
}
@@ -185,8 +185,9 @@ public void callObservers(Change<E> c) {

@Override
public Object[] toArray() {
Object[] arr = new Object[size()];
for (int i = 0; i < size(); i++) {
int max = size();
Object[] arr = new Object[max];
for (int i = 0; i < max; i++) {
arr[i] = get(i);
}
return arr;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -626,6 +626,7 @@ private void quietClearSelection() {
class SelectedIndicesList extends ReadOnlyUnbackedObservableList<Integer> {
private final BitSet bitset;

private int size = -1;
private int lastGetIndex = -1;
private int lastGetValue = -1;

@@ -694,6 +695,7 @@ public void set(int index) {
}

_beginChange();
size = -1;
bitset.set(index);
int indicesIndex = indexOf(index);
_nextAdd(indicesIndex, indicesIndex + 1);
@@ -714,6 +716,7 @@ public void set(int index, boolean isSet) {

public void set(int index, int end, boolean isSet) {
_beginChange();
size = -1;
if (isSet) {
bitset.set(index, end, isSet);
int indicesIndex = indexOf(index);
@@ -791,6 +794,7 @@ public void set(int index, int... indices) {
public void clear() {
_beginChange();
List<Integer> removed = bitset.stream().boxed().collect(Collectors.toList());
size = 0;
bitset.clear();
_nextRemove(0, removed);
_endChange();
@@ -800,6 +804,7 @@ public void clear(int index) {
if (!bitset.get(index)) return;

_beginChange();
size = -1;
bitset.clear(index);
_nextRemove(index, index);
_endChange();
@@ -855,7 +860,11 @@ public boolean isNotSelected(int index) {

/** Returns number of true bits in BitSet */
This conversation was marked as resolved by yososs

This comment has been minimized.

@aghaisas

aghaisas Sep 14, 2020
Collaborator

Method description and work done by it is no more matching. Can you please update the comment?

This comment has been minimized.

@yososs

yososs Sep 22, 2020
Author

This comment is correct. this.size is the cache.

@Override public int size() {
return bitset.cardinality();
if (size >= 0) {
return size;
}
size = bitset.cardinality();
return size;
}

/** Returns the number of bits reserved in the BitSet */
@@ -864,8 +873,48 @@ public int bitsetSize() {
}

@Override public int indexOf(Object obj) {
reset();
return super.indexOf(obj);
if (!(obj instanceof Number)) {
return -1;
}
Number n = (Number) obj;
int index = n.intValue();
if (!bitset.get(index)) {
return -1;
}
// is left most bit
if (index == 0) {
return 0;
}

// is right most bit
if (index == bitset.length()-1) {
return size()-1;
}

// count right bit
if (index > bitset.length()/2) {
int count = 1;
for (;;) {
index = bitset.nextSetBit(index + 1);
if (index < 0) {
This conversation was marked as resolved by yososs

This comment has been minimized.

@aghaisas

aghaisas Sep 14, 2020
Collaborator

As we are checking for nextSetBit, shouldn't we be checking for overflow rather than underflow?
Refer - javadoc

This comment has been minimized.

@yososs

yososs Sep 22, 2020
Author

Since it cannot be loaded with a smaller number of items than Integer.MAX_VALUE (it looks like it freezes), overflow does not occur in the actual usage environment.

break;
}
count++;
}
return size() - count;
}

// count left bit
// return (int)bitset.stream().takeWhile(i->i<index).count();
int count = 0;
for (;;) {
index = bitset.previousSetBit(index-1);
if (index < 0) {
break;
}
count++;
}
return count;
}

@Override public boolean contains(Object o) {
ProTip! Use n and p to navigate between commits in a pull request.