Skip to content

Commit b552f97

Browse files
committed
lib: remove unnecessary optional chain in diagnostics_channel publish()
ActiveChannel.publish() accessed this._subscribers with optional chaining (subscribers?.length || 0). This is unnecessary because: - _subscribers is always initialized to [] by markActive() before any ActiveChannel method can be called - maybeMarkInactive() sets _subscribers back to undefined only after switching the prototype back to Channel.prototype, so ActiveChannel methods are never reachable with a nullish _subscribers Use subscribers.length directly. Signed-off-by: Divyanshu Sharma <divyanshu88999@gmail.com>
1 parent 6d23c3b commit b552f97

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/diagnostics_channel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class ActiveChannel {
300300
publish(data) {
301301
// Normal path, no ALS lookup, plain function call, zero overhead.
302302
const subscribers = this._subscribers;
303-
for (let i = 0; i < (subscribers?.length || 0); i++) {
303+
for (let i = 0; i < subscribers.length; i++) {
304304
try {
305305
subscribers[i](data, this.name);
306306
} catch (err) {

0 commit comments

Comments
 (0)