Skip to content

Commit

Permalink
Add caching for expensive methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Mar 25, 2020
1 parent 6193017 commit 1eba9dd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion byte-buddy-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.7</version>
<version>1.10.8</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions byte-buddy-dep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>1.10.7</version>
<version>1.10.8</version>
<executions>
<execution>
<phase>compile</phase>
Expand All @@ -116,13 +116,13 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.7</version>
<version>1.10.8</version>
<plugin>net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields</plugin>
</transformation>
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.7</version>
<version>1.10.8</version>
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
</transformation>
</transformations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public SignatureToken asSignatureToken() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return getDeclaringType().hashCode() + 31 * (17 + getName().hashCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ public boolean isBridgeCompatible(TypeToken typeToken) {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
int hashCode = 17 + getDeclaringType().hashCode();
hashCode = 31 * hashCode + getInternalName().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.bytebuddy.description.method;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.bytebuddy.build.CachedReturnPlugin;
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable;
Expand Down Expand Up @@ -186,6 +187,7 @@ public Token asToken(ElementMatcher<? super TypeDescription> matcher) {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return getDeclaringMethod().hashCode() ^ getIndex();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,7 @@ public Iterator<TypeDefinition> iterator() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return asErasure().hashCode();
}
Expand Down Expand Up @@ -4313,6 +4314,7 @@ public StackSize getStackSize() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return getSort().isNonGeneric()
? asErasure().hashCode()
Expand Down Expand Up @@ -4591,6 +4593,7 @@ public StackSize getStackSize() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
int lowerHash = 1, upperHash = 1;
for (Generic lowerBound : getLowerBounds()) {
Expand Down Expand Up @@ -5017,6 +5020,7 @@ public StackSize getStackSize() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
int result = 1;
for (Generic typeArgument : getTypeArguments()) {
Expand Down Expand Up @@ -5601,6 +5605,7 @@ public Iterator<TypeDefinition> iterator() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return getTypeVariableSource().hashCode() ^ getSymbol().hashCode();
}
Expand Down Expand Up @@ -6153,6 +6158,7 @@ public boolean represents(java.lang.reflect.Type type) {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return resolve().hashCode();
}
Expand Down Expand Up @@ -7932,6 +7938,7 @@ public Iterator<TypeDefinition> iterator() {
}

@Override
@CachedReturnPlugin.Enhance
public int hashCode() {
return getName().hashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package net.bytebuddy.dynamic.scaffold;

import net.bytebuddy.build.CachedReturnPlugin;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.annotation.AnnotationValue;
Expand Down Expand Up @@ -1123,6 +1124,7 @@ public TypeDescription getDeclaringType() {
/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance
public Generic getSuperClass() {
return superClass == null
? Generic.UNDEFINED
Expand All @@ -1132,27 +1134,31 @@ public Generic getSuperClass() {
/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance
public TypeList.Generic getInterfaces() {
return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(interfaceTypes, TypeDescription.Generic.Visitor.Substitutor.ForAttachment.of(this));
}

/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance
public FieldList<FieldDescription.InDefinedShape> getDeclaredFields() {
return new FieldList.ForTokens(this, fieldTokens);
}

/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance
public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods() {
return new MethodList.ForTokens(this, methodTokens);
}

/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance
public TypeList.Generic getTypeVariables() {
return TypeList.Generic.ForDetachedTypes.attachVariables(this, typeVariables);
}
Expand Down

0 comments on commit 1eba9dd

Please sign in to comment.