Skip to content

Commit

Permalink
Merge pull request #371 from Ladicek/improve-allocations-in-annotatio…
Browse files Browse the repository at this point in the history
…n-overlay

improve allocations in the annotation overlay
  • Loading branch information
Ladicek authored May 17, 2024
2 parents ef5859a + 29acecc commit 3134b6f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/src/main/java/org/jboss/jandex/AnnotationOverlayImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,17 @@ public final Collection<AnnotationInstance> annotations(Declaration declaration)

Set<AnnotationInstance> getAnnotationsFor(Declaration declaration) {
EquivalenceKey key = EquivalenceKey.of(declaration);
Set<AnnotationInstance> annotations = overlay.get(key);

if (annotations == null) {
Collection<AnnotationInstance> original = new HashSet<>(getOriginalAnnotations(declaration));
Set<AnnotationInstance> annotations = overlay.computeIfAbsent(key, ignored -> {
Set<AnnotationInstance> original = getOriginalAnnotations(declaration);
TransformationContextImpl transformationContext = new TransformationContextImpl(declaration, original);
for (AnnotationTransformation transformation : transformations) {
if (transformation.supports(declaration.kind())) {
transformation.apply(transformationContext);
}
}
Set<AnnotationInstance> result = transformationContext.annotations;
annotations = original.equals(result) ? SENTINEL : Collections.unmodifiableSet(result);
overlay.put(key, annotations);
}
return original.equals(result) ? SENTINEL : Collections.unmodifiableSet(result);
});

if (annotations == SENTINEL) {
annotations = getOriginalAnnotations(declaration);
Expand Down

0 comments on commit 3134b6f

Please sign in to comment.