use 'sorted' flag in indexOf
This commit is contained in:
@@ -566,12 +566,20 @@ public final class IntList implements Serializable, Cloneable {
|
||||
* if offset is negative, or larger than the size of the list
|
||||
*/
|
||||
public int indexOf(final int value, final int offset) {
|
||||
for (int i = offset; i < index; i++) {
|
||||
if (data[i] == value) {
|
||||
return i;
|
||||
|
||||
int result = -1;
|
||||
if (sorted) {
|
||||
final int insertionPoint = Arrays.binarySearch(data, offset, size(), value);
|
||||
result = insertionPoint < 0 ? -1 : insertionPoint;
|
||||
} else {
|
||||
for (int i = offset; i < index; i++) {
|
||||
if (data[i] == value) {
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user