Skip to content

Commit 9514c3a

Browse files
committed
perf(WT-1083): use Set<String> for handshake line lookup in callsToTerminate
Reduces membership checks from O(n) to O(1) per active call.
1 parent ba0f66e commit 9514c3a

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

lib/features/call/bloc/call_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ class CallBloc extends Bloc<CallEvent, CallState> with WidgetsBindingObserver im
25772577
final activeLineCallIds = [
25782578
...stateHandshake.lines,
25792579
stateHandshake.guestLine,
2580-
].whereType<Line>().map((line) => line.callId).toList();
2580+
].whereType<Line>().map((line) => line.callId).toSet();
25812581

25822582
for (final callId in state.callsToTerminate(activeLineCallIds)) {
25832583
final activeCall = state.retrieveActiveCall(callId);

lib/features/call/bloc/call_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CallState with _$CallState {
9999

100100
bool get shouldListenToProximity => isActive && isVoiceChat && minimized != true;
101101

102-
List<String> callsToTerminate(List<String> activeLineCallIds) {
102+
List<String> callsToTerminate(Set<String> activeLineCallIds) {
103103
final result = <String>[];
104104
activeCallsLoop:
105105
for (final activeCall in activeCalls) {

test/features/call/bloc/call_state_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,13 +1270,13 @@ void main() {
12701270
test('terminates call absent from handshake lines', () {
12711271
final call = _makeCall(callId: 'c1', processingStatus: CallProcessingStatus.connected);
12721272
final state = CallState(activeCalls: [call]);
1273-
expect(state.callsToTerminate([]), ['c1']);
1273+
expect(state.callsToTerminate({}), ['c1']);
12741274
});
12751275

12761276
test('keeps call that is present in handshake lines', () {
12771277
final call = _makeCall(callId: 'c1', processingStatus: CallProcessingStatus.connected);
12781278
final state = CallState(activeCalls: [call]);
1279-
expect(state.callsToTerminate(['c1']), isEmpty);
1279+
expect(state.callsToTerminate({'c1'}), isEmpty);
12801280
});
12811281

12821282
test('keeps outgoing call with isPreOfferSent status absent from handshake', () {
@@ -1289,7 +1289,7 @@ void main() {
12891289
]) {
12901290
final call = _makeCall(callId: 'c1', direction: CallDirection.outgoing, processingStatus: status);
12911291
final state = CallState(activeCalls: [call]);
1292-
expect(state.callsToTerminate([]), isEmpty, reason: 'should skip $status');
1292+
expect(state.callsToTerminate({}), isEmpty, reason: 'should skip $status');
12931293
}
12941294
});
12951295

@@ -1300,7 +1300,7 @@ void main() {
13001300
processingStatus: CallProcessingStatus.outgoingOfferSent,
13011301
);
13021302
final state = CallState(activeCalls: [call]);
1303-
expect(state.callsToTerminate([]), ['c1']);
1303+
expect(state.callsToTerminate({}), ['c1']);
13041304
});
13051305

13061306
test('terminates outgoing call at outgoingRinging absent from handshake', () {
@@ -1310,7 +1310,7 @@ void main() {
13101310
processingStatus: CallProcessingStatus.outgoingRinging,
13111311
);
13121312
final state = CallState(activeCalls: [call]);
1313-
expect(state.callsToTerminate([]), ['c1']);
1313+
expect(state.callsToTerminate({}), ['c1']);
13141314
});
13151315

13161316
test('keeps outgoing isPreOfferSent call even if other calls are terminated', () {
@@ -1321,13 +1321,13 @@ void main() {
13211321
);
13221322
final dead = _makeCall(callId: 'dead', processingStatus: CallProcessingStatus.connected);
13231323
final state = CallState(activeCalls: [inFlight, dead]);
1324-
expect(state.callsToTerminate([]), ['dead']);
1324+
expect(state.callsToTerminate({}), ['dead']);
13251325
});
13261326

13271327
test('returns empty when all calls are in handshake lines', () {
13281328
final calls = [_makeCall(callId: 'c1'), _makeCall(callId: 'c2')];
13291329
final state = CallState(activeCalls: calls);
1330-
expect(state.callsToTerminate(['c1', 'c2']), isEmpty);
1330+
expect(state.callsToTerminate({'c1', 'c2'}), isEmpty);
13311331
});
13321332
});
13331333
}

0 commit comments

Comments
 (0)