Simplify ComputeInt32Size to call ComputeInt32SizeNoTag.

pull/515/head
Jon Skeet 10 years ago
parent 1b71db1180
commit 5685e98711
  1. 12
      csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs

@ -91,15 +91,7 @@ namespace Google.Protobuf
/// </summary> /// </summary>
public static int ComputeInt32Size(int fieldNumber, int value) public static int ComputeInt32Size(int fieldNumber, int value)
{ {
if (value >= 0) return ComputeTagSize(fieldNumber) + ComputeInt32SizeNoTag(value);
{
return ComputeTagSize(fieldNumber) + ComputeRawVarint32Size((uint) value);
}
else
{
// Must sign-extend.
return ComputeTagSize(fieldNumber) + 10;
}
} }
/// <summary> /// <summary>
@ -418,7 +410,6 @@ namespace Google.Protobuf
/// </summary> /// </summary>
public static int ComputeRawVarint32Size(uint value) public static int ComputeRawVarint32Size(uint value)
{ {
// TODO(jonskeet): Look at optimizing this to just hard-coded comparisons.
if ((value & (0xffffffff << 7)) == 0) if ((value & (0xffffffff << 7)) == 0)
{ {
return 1; return 1;
@ -443,7 +434,6 @@ namespace Google.Protobuf
/// </summary> /// </summary>
public static int ComputeRawVarint64Size(ulong value) public static int ComputeRawVarint64Size(ulong value)
{ {
// TODO(jonskeet): Look at optimizing this to just hard-coded comparisons.
if ((value & (0xffffffffffffffffL << 7)) == 0) if ((value & (0xffffffffffffffffL << 7)) == 0)
{ {
return 1; return 1;

Loading…
Cancel
Save