Skip to content

Commit c6553d1

Browse files
committed
Removed some unnecessary bounds checks
1 parent 9809522 commit c6553d1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Microsoft.Toolkit.Mvvm/Messaging/WeakRefMessenger.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,15 @@ public TMessage Send<TMessage, TToken>(TMessage message, TToken token)
206206
ReadOnlySpan<object>
207207
recipientsSpan = recipients.Span,
208208
handlersSpan = handlers.Span;
209-
int handlersCount = recipients.Count;
210209

211-
for (int i = 0; i < handlersCount; i++)
210+
for (int i = 0; i < recipientsSpan.Length; i++)
212211
{
213212
// Just like in the other messenger, here we need an unsafe cast to be able to
214213
// invoke a generic delegate with a contravariant input argument, with a less
215214
// derived reference, without reflection. This is guaranteed to work by how the
216215
// messenger tracks registered recipients and their associated handlers, so the
217216
// type conversion will always be valid (the recipients are the rigth instances).
218-
Unsafe.As<MessageHandler<object, TMessage>>(handlersSpan[i])(recipientsSpan![i], message);
217+
Unsafe.As<MessageHandler<object, TMessage>>(handlersSpan[i])(recipientsSpan[i], message);
219218
}
220219
}
221220
finally

0 commit comments

Comments
 (0)