From 5e8af8439a9806cf23cde583f89e80530539d50f Mon Sep 17 00:00:00 2001 From: Tyler Benson Date: Tue, 7 Jan 2020 17:10:01 -0800 Subject: [PATCH] Optimize HasSuperMethodMatcher logic Instead of filtering then iterating, just iterate through everything and apply filter inline. This will help avoid allocation for filter iterator and improve if early match is found. --- .../trace/agent/tooling/ByteBuddyElementMatchers.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ByteBuddyElementMatchers.java b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ByteBuddyElementMatchers.java index 6dbaa8e594..8b23e03422 100644 --- a/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ByteBuddyElementMatchers.java +++ b/dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/ByteBuddyElementMatchers.java @@ -328,9 +328,8 @@ public class ByteBuddyElementMatchers { final Set checkedInterfaces = new HashSet<>(); while (declaringType != null) { - for (final MethodDescription methodDescription : - declaringType.getDeclaredMethods().filter(signatureMatcher)) { - if (matcher.matches(methodDescription)) { + for (final MethodDescription methodDescription : declaringType.getDeclaredMethods()) { + if (signatureMatcher.matches(methodDescription) && matcher.matches(methodDescription)) { return true; } }