From 1eba9ddf1f2944db18a8362da84ac0dfc2253b55 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 25 Mar 2020 09:23:55 +0100 Subject: [PATCH] Add caching for expensive methods. --- byte-buddy-agent/pom.xml | 2 +- byte-buddy-dep/pom.xml | 6 +++--- .../net/bytebuddy/description/field/FieldDescription.java | 1 + .../bytebuddy/description/method/MethodDescription.java | 1 + .../bytebuddy/description/method/ParameterDescription.java | 2 ++ .../net/bytebuddy/description/type/TypeDescription.java | 7 +++++++ .../net/bytebuddy/dynamic/scaffold/InstrumentedType.java | 6 ++++++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/byte-buddy-agent/pom.xml b/byte-buddy-agent/pom.xml index cc8341ade48..0132d282472 100644 --- a/byte-buddy-agent/pom.xml +++ b/byte-buddy-agent/pom.xml @@ -69,7 +69,7 @@ net.bytebuddy byte-buddy - 1.10.7 + 1.10.8 test diff --git a/byte-buddy-dep/pom.xml b/byte-buddy-dep/pom.xml index caa9eed92ba..2d8dc58d71a 100644 --- a/byte-buddy-dep/pom.xml +++ b/byte-buddy-dep/pom.xml @@ -101,7 +101,7 @@ net.bytebuddy byte-buddy-maven-plugin - 1.10.7 + 1.10.8 compile @@ -116,13 +116,13 @@ net.bytebuddy byte-buddy - 1.10.7 + 1.10.8 net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields net.bytebuddy byte-buddy - 1.10.7 + 1.10.8 net.bytebuddy.build.CachedReturnPlugin diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/field/FieldDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/field/FieldDescription.java index 461a7b7daec..4979f4cedc7 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/field/FieldDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/field/FieldDescription.java @@ -192,6 +192,7 @@ public SignatureToken asSignatureToken() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return getDeclaringType().hashCode() + 31 * (17 + getName().hashCode()); } diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java index 9ab0cc62965..2a2a5c491cf 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/MethodDescription.java @@ -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(); diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/ParameterDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/ParameterDescription.java index c0718e35d99..898ccb3bd74 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/ParameterDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/method/ParameterDescription.java @@ -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; @@ -186,6 +187,7 @@ public Token asToken(ElementMatcher matcher) { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return getDeclaringMethod().hashCode() ^ getIndex(); } diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java index 95bfcf520c5..8f19e8f9391 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java @@ -3773,6 +3773,7 @@ public Iterator iterator() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return asErasure().hashCode(); } @@ -4313,6 +4314,7 @@ public StackSize getStackSize() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return getSort().isNonGeneric() ? asErasure().hashCode() @@ -4591,6 +4593,7 @@ public StackSize getStackSize() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { int lowerHash = 1, upperHash = 1; for (Generic lowerBound : getLowerBounds()) { @@ -5017,6 +5020,7 @@ public StackSize getStackSize() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { int result = 1; for (Generic typeArgument : getTypeArguments()) { @@ -5601,6 +5605,7 @@ public Iterator iterator() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return getTypeVariableSource().hashCode() ^ getSymbol().hashCode(); } @@ -6153,6 +6158,7 @@ public boolean represents(java.lang.reflect.Type type) { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return resolve().hashCode(); } @@ -7932,6 +7938,7 @@ public Iterator iterator() { } @Override + @CachedReturnPlugin.Enhance public int hashCode() { return getName().hashCode(); } diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/InstrumentedType.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/InstrumentedType.java index f73a086e4ca..2de3c1ff9f6 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/InstrumentedType.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/InstrumentedType.java @@ -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; @@ -1123,6 +1124,7 @@ public TypeDescription getDeclaringType() { /** * {@inheritDoc} */ + @CachedReturnPlugin.Enhance public Generic getSuperClass() { return superClass == null ? Generic.UNDEFINED @@ -1132,6 +1134,7 @@ public Generic getSuperClass() { /** * {@inheritDoc} */ + @CachedReturnPlugin.Enhance public TypeList.Generic getInterfaces() { return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(interfaceTypes, TypeDescription.Generic.Visitor.Substitutor.ForAttachment.of(this)); } @@ -1139,6 +1142,7 @@ public TypeList.Generic getInterfaces() { /** * {@inheritDoc} */ + @CachedReturnPlugin.Enhance public FieldList getDeclaredFields() { return new FieldList.ForTokens(this, fieldTokens); } @@ -1146,6 +1150,7 @@ public FieldList getDeclaredFields() { /** * {@inheritDoc} */ + @CachedReturnPlugin.Enhance public MethodList getDeclaredMethods() { return new MethodList.ForTokens(this, methodTokens); } @@ -1153,6 +1158,7 @@ public MethodList getDeclaredMethods() { /** * {@inheritDoc} */ + @CachedReturnPlugin.Enhance public TypeList.Generic getTypeVariables() { return TypeList.Generic.ForDetachedTypes.attachVariables(this, typeVariables); }