Commit c58b2c66 authored by Jon Skeet's avatar Jon Skeet

Merge pull request #352 from jtattermusch/csharp_performance_fix

Performance optimization for small messages without unknown fields
parents 34fb6669 6f9da37b
......@@ -125,9 +125,13 @@ namespace Google.ProtocolBuffers
/// </summary>
public void WriteTo(ICodedOutputStream output)
{
foreach (KeyValuePair<int, UnknownField> entry in fields)
// Avoid creating enumerator for the most common code path.
if (fields.Count > 0)
{
entry.Value.WriteTo(entry.Key, output);
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
entry.Value.WriteTo(entry.Key, output);
}
}
}
......@@ -138,6 +142,12 @@ namespace Google.ProtocolBuffers
{
get
{
// Avoid creating enumerator for the most common code path.
if (fields.Count == 0)
{
return 0;
}
int result = 0;
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
......@@ -209,9 +219,13 @@ namespace Google.ProtocolBuffers
/// </summary>
public void WriteAsMessageSetTo(ICodedOutputStream output)
{
foreach (KeyValuePair<int, UnknownField> entry in fields)
// Avoid creating enumerator for the most common code path.
if (fields.Count > 0)
{
entry.Value.WriteAsMessageSetExtensionTo(entry.Key, output);
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
entry.Value.WriteAsMessageSetExtensionTo(entry.Key, output);
}
}
}
......@@ -223,6 +237,12 @@ namespace Google.ProtocolBuffers
{
get
{
// Avoid creating enumerator for the most common code path.
if (fields.Count == 0)
{
return 0;
}
int result = 0;
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment