Skip to content

Commit d1f0e45

Browse files
committed
remove enumerator allocation on IList<T> / use List type instead of interface
1 parent ccfddef commit d1f0e45

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

projects/RabbitMQ.Client/client/api/ConnectionFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ public Uri Uri
329329
public IAuthMechanismFactory AuthMechanismFactory(IList<string> mechanismNames)
330330
{
331331
// Our list is in order of preference, the server one is not.
332-
foreach (IAuthMechanismFactory factory in AuthMechanisms)
332+
for (int index = 0; index < AuthMechanisms.Count; index++)
333333
{
334+
IAuthMechanismFactory factory = AuthMechanisms[index];
334335
string factoryName = factory.Name;
335336
if (mechanismNames.Any<string>(x => string.Equals(x, factoryName, StringComparison.OrdinalIgnoreCase)))
336337
{
337338
return factory;
338339
}
339340
}
341+
340342
return null;
341343
}
342344

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,9 @@ public void PrettyPrintShutdownReport()
730730
{
731731
Console.Error.WriteLine(
732732
"Log of errors while closing connection {0}:", this);
733-
foreach (ShutdownReportEntry entry in ShutdownReport)
733+
for (int index = 0; index < ShutdownReport.Count; index++)
734734
{
735-
Console.Error.WriteLine(
736-
entry.ToString());
735+
Console.Error.WriteLine(ShutdownReport[index].ToString());
737736
}
738737
}
739738
}

projects/RabbitMQ.Client/client/impl/WireFormatting.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public static void DecimalToAmqp(decimal value, out byte scale, out int mantissa
9595

9696
public static IList ReadArray(ReadOnlyMemory<byte> memory, out int bytesRead)
9797
{
98-
IList array = new List<object>();
99-
long arrayLength = NetworkOrderDeserializer.ReadUInt32(memory);
98+
uint arrayLength = NetworkOrderDeserializer.ReadUInt32(memory);
99+
List<object> array = new List<object>((int)arrayLength);
100100
bytesRead = 4;
101101
while (bytesRead - 4 < arrayLength)
102102
{
@@ -247,9 +247,9 @@ public static int WriteArray(Memory<byte> memory, IList val)
247247
else
248248
{
249249
int bytesWritten = 0;
250-
foreach (object entry in val)
250+
for (int index = 0; index < val.Count; index++)
251251
{
252-
bytesWritten += WriteFieldValue(memory.Slice(4 + bytesWritten), entry); ;
252+
bytesWritten += WriteFieldValue(memory.Slice(4 + bytesWritten), val[index]);
253253
}
254254

255255
NetworkOrderSerializer.WriteUInt32(memory, (uint)bytesWritten);
@@ -265,9 +265,9 @@ public static int GetArrayByteCount(IList val)
265265
return byteCount;
266266
}
267267

268-
foreach (object entry in val)
268+
for (int index = 0; index < val.Count; index++)
269269
{
270-
byteCount += GetFieldValueByteCount(entry);
270+
byteCount += GetFieldValueByteCount(val[index]);
271271
}
272272

273273
return byteCount;

0 commit comments

Comments
 (0)