From 5e8d6a1f93c51a719c13d7dc263097bec707b11f Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 3 Jul 2024 16:30:52 +0530 Subject: [PATCH] [bidi][java] Avoid creating new instances of log entry event --- .../src/org/openqa/selenium/bidi/module/LogInspector.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/java/src/org/openqa/selenium/bidi/module/LogInspector.java b/java/src/org/openqa/selenium/bidi/module/LogInspector.java index 27c2adae27452..c897fd0a1df57 100644 --- a/java/src/org/openqa/selenium/bidi/module/LogInspector.java +++ b/java/src/org/openqa/selenium/bidi/module/LogInspector.java @@ -24,6 +24,7 @@ import java.util.function.Consumer; import org.openqa.selenium.WebDriver; import org.openqa.selenium.bidi.BiDi; +import org.openqa.selenium.bidi.Event; import org.openqa.selenium.bidi.HasBiDi; import org.openqa.selenium.bidi.log.BaseLogEntry; import org.openqa.selenium.bidi.log.ConsoleLogEntry; @@ -36,7 +37,7 @@ import org.openqa.selenium.internal.Require; public class LogInspector implements AutoCloseable { - + private final Event logEntryAddedEvent; private final Set browsingContextIds; private final BiDi bidi; @@ -59,6 +60,7 @@ public LogInspector(Set browsingContextIds, WebDriver driver) { this.bidi = ((HasBiDi) driver).getBiDi(); this.browsingContextIds = browsingContextIds; + this.logEntryAddedEvent = Log.entryAdded(); } public long onConsoleEntry(Consumer consumer) { @@ -165,9 +167,9 @@ public void onLog(Consumer consumer, FilterBy filter) { private long addLogEntryAddedListener(Consumer consumer) { if (browsingContextIds.isEmpty()) { - return this.bidi.addListener(Log.entryAdded(), consumer); + return this.bidi.addListener(this.logEntryAddedEvent, consumer); } else { - return this.bidi.addListener(browsingContextIds, Log.entryAdded(), consumer); + return this.bidi.addListener(browsingContextIds, this.logEntryAddedEvent, consumer); } }