Skip to content

Commit a6b0919

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

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,16 @@ public Uri Uri
334334
public IAuthMechanismFactory AuthMechanismFactory(IList<string> mechanismNames)
335335
{
336336
// Our list is in order of preference, the server one is not.
337-
foreach (IAuthMechanismFactory factory in AuthMechanisms)
337+
for (int index = 0; index < AuthMechanisms.Count; index++)
338338
{
339+
IAuthMechanismFactory factory = AuthMechanisms[index];
339340
string factoryName = factory.Name;
340341
if (mechanismNames.Any<string>(x => string.Equals(x, factoryName, StringComparison.OrdinalIgnoreCase)))
341342
{
342343
return factory;
343344
}
344345
}
346+
345347
return null;
346348
}
347349

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ internal static List<OutboundFrame> CalculateFrames(int channelNumber, Connectio
138138
{
139139
var frames = new List<OutboundFrame>();
140140

141-
foreach (Command cmd in commands)
141+
for (int index = 0; index < commands.Count; index++)
142142
{
143+
Command cmd = commands[index];
143144
frames.Add(new MethodOutboundFrame(channelNumber, cmd.Method));
144145
if (cmd.Method.HasContent)
145146
{

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)