aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/CodedInputStream.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-08 17:40:51 -0500
committerrogerk <devnull@localhost>2011-06-08 17:40:51 -0500
commit4ba365d7932ca661640a402c93d2dfb2816ffd62 (patch)
tree2dec30345745badd00ebad92a83227237c4c0d47 /src/ProtocolBuffers/CodedInputStream.cs
parent2772dfe8a1eae7c942bb50d84bda3f45b5d7b683 (diff)
downloadprotobuf-4ba365d7932ca661640a402c93d2dfb2816ffd62.tar.gz
protobuf-4ba365d7932ca661640a402c93d2dfb2816ffd62.tar.bz2
protobuf-4ba365d7932ca661640a402c93d2dfb2816ffd62.zip
Performance fix for double/float on read
Diffstat (limited to 'src/ProtocolBuffers/CodedInputStream.cs')
-rw-r--r--src/ProtocolBuffers/CodedInputStream.cs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs
index 4f9bdc23..105dc378 100644
--- a/src/ProtocolBuffers/CodedInputStream.cs
+++ b/src/ProtocolBuffers/CodedInputStream.cs
@@ -204,15 +204,22 @@ namespace Google.ProtocolBuffers
public bool ReadDouble(ref double value)
{
#if SILVERLIGHT2 || COMPACT_FRAMEWORK_35
- byte[] rawBytes = ReadRawBytes(8);
- if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
- value = BitConverter.ToDouble(rawBytes, 0);
- return true;
+ if (BitConverter.IsLittleEndian && 8 <= bufferSize - bufferPos)
+ {
+ value = BitConverter.ToDouble(buffer, bufferPos);
+ bufferPos += 8;
+ }
+ else
+ {
+ byte[] rawBytes = ReadRawBytes(8);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ value = BitConverter.ToDouble(rawBytes, 0);
+ }
#else
value = BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
- return true;
#endif
+ return true;
}
/// <summary>
@@ -220,10 +227,18 @@ namespace Google.ProtocolBuffers
/// </summary>
public bool ReadFloat(ref float value)
{
- byte[] rawBytes = ReadRawBytes(4);
- if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
- value = BitConverter.ToSingle(rawBytes, 0);
+ if (BitConverter.IsLittleEndian && 4 <= bufferSize - bufferPos)
+ {
+ value = BitConverter.ToSingle(buffer, bufferPos);
+ bufferPos += 4;
+ }
+ else
+ {
+ byte[] rawBytes = ReadRawBytes(4);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ value = BitConverter.ToSingle(rawBytes, 0);
+ }
return true;
}