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
......@@ -124,12 +124,16 @@ namespace Google.ProtocolBuffers
/// Serializes the set and writes it to <paramref name="output"/>.
/// </summary>
public void WriteTo(ICodedOutputStream output)
{
// Avoid creating enumerator for the most common code path.
if (fields.Count > 0)
{
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
entry.Value.WriteTo(entry.Key, output);
}
}
}
/// <summary>
/// Gets the number of bytes required to encode this set.
......@@ -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)
{
......@@ -208,12 +218,16 @@ namespace Google.ProtocolBuffers
/// the MessageSet wire format.
/// </summary>
public void WriteAsMessageSetTo(ICodedOutputStream output)
{
// Avoid creating enumerator for the most common code path.
if (fields.Count > 0)
{
foreach (KeyValuePair<int, UnknownField> entry in fields)
{
entry.Value.WriteAsMessageSetExtensionTo(entry.Key, output);
}
}
}
/// <summary>
/// Gets the number of bytes required to encode this set using the MessageSet
......@@ -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