8325679: Optimize ArrayList subList sort

Reviewed-by: liach
This commit is contained in:
Attila Szegedi 2024-09-04 13:40:40 +00:00
parent bd8569bc6c
commit c7d15f1fe0
2 changed files with 16 additions and 5 deletions

View file

@ -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.
*
* 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
@SuppressWarnings("unchecked")
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;
Arrays.sort((E[]) elementData, 0, size, c);
Arrays.sort((E[]) elementData, fromIndex, toIndex, c);
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
modCount++;