Skip to content

Commit

Permalink
SONARJAVA-3317 To improve performance cache JTypeSymbol.memberSymbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Apr 8, 2020
1 parent 50c8c6e commit ecf8f9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions java-frontend/src/main/java/org/sonar/java/model/JTypeSymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ final class JTypeSymbol extends JSymbol implements Symbol.TypeSymbol {
*/
private List<Type> interfaces;

/**
* Cache for {@link #memberSymbols()}.
*/
private Collection<Symbol> memberSymbols;

final SpecialField superSymbol = new SpecialField() {
@Override
public String name() {
Expand Down Expand Up @@ -118,6 +123,13 @@ public List<Type> interfaces() {

@Override
public Collection<Symbol> memberSymbols() {
if (memberSymbols == null) {
memberSymbols = convertMemberSymbols();
}
return memberSymbols;
}

private Collection<Symbol> convertMemberSymbols() {
Collection<Symbol> members = new ArrayList<>();
for (ITypeBinding b : typeBinding().getDeclaredTypes()) {
members.add(sema.typeSymbol(b));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void type() {
@Test
void symbol_type() {
assertAll(
() -> assertThat(instanceSize(JTypeSymbol.class, X86_64)).isEqualTo(88),
() -> assertThat(instanceSize(JTypeSymbol.class, X86_64_COOPS)).isEqualTo(48)
() -> assertThat(instanceSize(JTypeSymbol.class, X86_64)).isEqualTo(96),
() -> assertThat(instanceSize(JTypeSymbol.class, X86_64_COOPS)).isEqualTo(56)
);
}

Expand Down

0 comments on commit ecf8f9f

Please sign in to comment.