8325679: Optimize ArrayList subList sort
Reviewed-by: liach
This commit is contained in:
parent
bd8569bc6c
commit
c7d15f1fe0
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -1582,6 +1582,13 @@ public class ArrayList<E> extends AbstractList<E>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sort(Comparator<? super E> c) {
|
||||||
|
checkForComodification();
|
||||||
|
root.sortRange(c, offset, offset + size);
|
||||||
|
updateSizeAndModCount(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1799,10 +1806,14 @@ public class ArrayList<E> extends AbstractList<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void sort(Comparator<? super E> c) {
|
public void sort(Comparator<? super E> c) {
|
||||||
|
sortRange(c, 0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void sortRange(Comparator<? super E> c, int fromIndex, int toIndex) {
|
||||||
final int expectedModCount = modCount;
|
final int expectedModCount = modCount;
|
||||||
Arrays.sort((E[]) elementData, 0, size, c);
|
Arrays.sort((E[]) elementData, fromIndex, toIndex, c);
|
||||||
if (modCount != expectedModCount)
|
if (modCount != expectedModCount)
|
||||||
throw new ConcurrentModificationException();
|
throw new ConcurrentModificationException();
|
||||||
modCount++;
|
modCount++;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,7 +50,7 @@ import java.util.function.Predicate;
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @summary Unit tests for extension methods on List
|
* @summary Unit tests for extension methods on List
|
||||||
* @bug 8023367 8037106
|
* @bug 8023367 8037106 8325679
|
||||||
* @library ../Collection/testlibrary
|
* @library ../Collection/testlibrary
|
||||||
* @build CollectionAsserts CollectionSupplier ExtendsAbstractList
|
* @build CollectionAsserts CollectionSupplier ExtendsAbstractList
|
||||||
* @run testng ListDefaults
|
* @run testng ListDefaults
|
||||||
|
Loading…
Reference in New Issue
Block a user