On Wed, 7 Oct 2020 18:34:23 GMT, yosbits 
<github.com+7517141+yos...@openjdk.org> wrote:

>> I plan to push changes that remain compatible, respecting the judgment of 
>> the project leader, but I would like to point
>> out the following:
>> There seems to be a problem with the reproduction code as follows.
>> 
>> * If there are duplicate items, the unselected parts will also be deleted.
>> * Using getSelectedIndices() is more advantageous in terms of performance 
>> than getSelectedItems ().
>> 
>> Therefore, this context should normally be avoided,
>> Seems like less important compatibility.
>
> **The next implementation will probably have a good balance between space and 
> time.**
> Unless you do something like delete the even or odd indexes
> The space efficiency is very high.
> 
> Currently being tested.
> 
>  Java
>     @Override
>     public boolean removeAll(Collection<?> c) {
>       // Throw NullPointerException if c is null
>         if (c.isEmpty() || this.isEmpty()) {
>             return false;
>         }
>         List<Integer> runLengths = new java.util.ArrayList<>();
>         {
>             int run = 0;
>             boolean flag = true;
>             for (int i=size()-1; i>=0; i--) {
>                 if (c.contains(get(i))==flag) {
>                     run++;
>                 } else {
>                     runLengths.add(run);
>                     run = 1;
>                     flag = !flag;
>                 }
>             }
>             if (run>0 && flag) {
>                 runLengths.add(run);
>             }
>         }
>         boolean flag = true;
>         boolean removed = false;
>         if(runLengths.size()>0) {
>             beginChange();
>             int cur = size()-1;
>             for (int run:runLengths) {
>                 if(flag) {
>                     for(int to=cur-run; cur > to; cur--) {
>                         remove(cur);
>                         removed = true;
>                     }
>                 }else {
>                     cur -= run;
>                 }
>                 flag = !flag;
>             }
>             endChange();
>             return removed;
>         }
>         return false;
>     }
> This implementation is more efficient by using an int [] array instead of an 
> ArrayList.
> 
> I'm planning to push it in a few days.

It seems that many people are interested, so I pushed the change.
I don't understand how to proceed with the review on Github correctly, so if I 
have anything to do, please comment.

 java
                    for(int to=cur-run; cur > to; cur--) {
                        remove(cur);
                    }
                    removed = true;



This can be moved out of the loop and will be included in the next change.

-------------

PR: https://git.openjdk.java.net/jfx/pull/305

Reply via email to