EventBus
EventBus copied to clipboard
Add `hasListeners()`/`hasAnyListeners()` to avoid unnecessary event object instantiation
Adds these static methods:
Event.hasListeners(bus)Event.hasAnyListeners()Event.getListenerListStatically()
Transformer changes getListenerListStatically() to grab the same static field that the instance method does.
The hasListeners()/hasAnyListeners() methods check the ListenerList's array size directly - no hashsets or additional memory overhead.
JMH benchmark results:
Benchmark Mode Cnt Score Error Units
EventBusBenchmark.testClassLoaderCombined avgt 15 42.212 � 0.436 ns/op
EventBusBenchmark.testClassLoaderCombinedHasAnyListeners avgt 15 34.442 � 0.791 ns/op
EventBusBenchmark.testClassLoaderCombinedHasListeners avgt 15 5.480 � 0.042 ns/op
EventBusBenchmark.testModLauncherCombined avgt 15 41.072 � 0.339 ns/op
EventBusBenchmark.testModLauncherCombinedHasAnyListeners avgt 15 34.047 � 0.224 ns/op
EventBusBenchmark.testModLauncherCombinedHasListeners avgt 15 5.510 � 0.042 ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombined avgt 15 170.711 � 3.025 ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombinedHasAnyListeners avgt 15 12.390 � 0.046 ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombinedHasListeners avgt 15 5.319 � 0.067 ns/op