-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
There may be a possible minor improvement in the binary searching done in AnnotationInstance by special-casing arrays of length 0 and 1, and using lambdas for the comparators. The use of the lambda relies on the fact that Arrays.binarySearch will pass the array entries as the first parameter of the comparator (AnnotationInstance#value(String) already relies on this). It should result in an allocation-free search.
For example:
static AnnotationInstance binarySearch(AnnotationInstance[] annotations, DotName name) {
if (annotations.length == 0) {
return null;
}
if (annotations.length == 1) {
return annotations[0].name().equals(name) ? annotations[0] : null;
}
// Relies on binarySearch passing array entries as the first comparator parameter
int i = Arrays.binarySearch(annotations, null, (entry, x) -> entry.name().compareTo(name));
return i >= 0 ? annotations[i] : null;
}Also, the create method AnnotationInstance instantiates an AnnotationValue name comparator which maybe could be a constant.
Metadata
Metadata
Assignees
Labels
No labels