Skip to content

Commit 5e8d6a1

Browse files
committed
[bidi][java] Avoid creating new instances of log entry event
1 parent 06e7b7a commit 5e8d6a1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

java/src/org/openqa/selenium/bidi/module/LogInspector.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.function.Consumer;
2525
import org.openqa.selenium.WebDriver;
2626
import org.openqa.selenium.bidi.BiDi;
27+
import org.openqa.selenium.bidi.Event;
2728
import org.openqa.selenium.bidi.HasBiDi;
2829
import org.openqa.selenium.bidi.log.BaseLogEntry;
2930
import org.openqa.selenium.bidi.log.ConsoleLogEntry;
@@ -36,7 +37,7 @@
3637
import org.openqa.selenium.internal.Require;
3738

3839
public class LogInspector implements AutoCloseable {
39-
40+
private final Event<LogEntry> logEntryAddedEvent;
4041
private final Set<String> browsingContextIds;
4142

4243
private final BiDi bidi;
@@ -59,6 +60,7 @@ public LogInspector(Set<String> browsingContextIds, WebDriver driver) {
5960

6061
this.bidi = ((HasBiDi) driver).getBiDi();
6162
this.browsingContextIds = browsingContextIds;
63+
this.logEntryAddedEvent = Log.entryAdded();
6264
}
6365

6466
public long onConsoleEntry(Consumer<ConsoleLogEntry> consumer) {
@@ -165,9 +167,9 @@ public void onLog(Consumer<LogEntry> consumer, FilterBy filter) {
165167

166168
private long addLogEntryAddedListener(Consumer<LogEntry> consumer) {
167169
if (browsingContextIds.isEmpty()) {
168-
return this.bidi.addListener(Log.entryAdded(), consumer);
170+
return this.bidi.addListener(this.logEntryAddedEvent, consumer);
169171
} else {
170-
return this.bidi.addListener(browsingContextIds, Log.entryAdded(), consumer);
172+
return this.bidi.addListener(browsingContextIds, this.logEntryAddedEvent, consumer);
171173
}
172174
}
173175

0 commit comments

Comments
 (0)