Need to cache the boolean. The list can be taken later as debug is expected to be slower

This commit is contained in:
Brian Devins-Suresh 2020-02-24 14:38:10 -05:00
parent 75af71584c
commit af67dfa720
2 changed files with 9 additions and 11 deletions

View File

@ -135,9 +135,9 @@ public interface Instrumenter {
if (null != muzzle) {
final boolean isMatch = muzzle.matches(classLoader);
if (!isMatch) {
if (log.isDebugEnabled()) {
final List<Reference.Mismatch> mismatches =
muzzle.getMismatchedReferenceSources(classLoader);
if (log.isDebugEnabled()) {
log.debug(
"Instrumentation muzzled: {} -- {} on {}",
instrumentationNames,

View File

@ -22,9 +22,8 @@ import net.bytebuddy.pool.TypePool;
/** Matches a set of references against a classloader. */
@Slf4j
public class ReferenceMatcher
implements WeakMap.ValueSupplier<ClassLoader, List<Reference.Mismatch>> {
private final WeakMap<ClassLoader, List<Reference.Mismatch>> mismatchCache = newWeakMap();
public class ReferenceMatcher implements WeakMap.ValueSupplier<ClassLoader, Boolean> {
private final WeakMap<ClassLoader, Boolean> mismatchCache = newWeakMap();
private final Reference[] references;
private final Set<String> helperClassNames;
@ -52,6 +51,11 @@ public class ReferenceMatcher
loader = Utils.getBootstrapProxy();
}
return mismatchCache.computeIfAbsent(loader, this);
}
@Override
public Boolean get(final ClassLoader loader) {
final List<Mismatch> mismatches = new ArrayList<>(0);
for (final Reference reference : references) {
@ -65,7 +69,6 @@ public class ReferenceMatcher
}
}
mismatchCache.put(loader, mismatches);
return mismatches.size() == 0;
}
@ -80,11 +83,6 @@ public class ReferenceMatcher
loader = Utils.getBootstrapProxy();
}
return mismatchCache.computeIfAbsent(loader, this);
}
@Override
public List<Mismatch> get(final ClassLoader loader) {
final List<Mismatch> mismatches = new ArrayList<>(0);
for (final Reference reference : references) {