Merge pull request #352 from jtattermusch/csharp_performance_fix

Performance optimization for small messages without unknown fields
pull/366/head
Jon Skeet 10 years ago
commit c58b2c6644
  1. 20
      csharp/src/ProtocolBuffers/UnknownFieldSet.cs

@ -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)
{

Loading…
Cancel
Save