diff options
author | Oli Wilkinson <oli@evolutional.co.uk> | 2015-12-12 11:39:57 -0500 |
---|---|---|
committer | Oli Wilkinson <oli@evolutional.co.uk> | 2015-12-12 11:39:57 -0500 |
commit | be11d2b6ef71f367817000b853724982992d2e45 (patch) | |
tree | aca9996584c029ee71e8824c78bf9de751245d97 /net | |
parent | b8187e5b8231148ba532a3f5dae035adfb43346b (diff) | |
download | flatbuffers-be11d2b6ef71f367817000b853724982992d2e45.tar.gz flatbuffers-be11d2b6ef71f367817000b853724982992d2e45.tar.bz2 flatbuffers-be11d2b6ef71f367817000b853724982992d2e45.zip |
C# performance optimization to Pad/Prep methods
Diffstat (limited to 'net')
-rwxr-xr-x | net/FlatBuffers/ByteBuffer.cs | 7 | ||||
-rw-r--r-- | net/FlatBuffers/FlatBufferBuilder.cs | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/net/FlatBuffers/ByteBuffer.cs b/net/FlatBuffers/ByteBuffer.cs index e2a5f2d8..37779b59 100755 --- a/net/FlatBuffers/ByteBuffer.cs +++ b/net/FlatBuffers/ByteBuffer.cs @@ -146,6 +146,13 @@ namespace FlatBuffers _buffer[offset] = value; } + public void PutByte(int offset, byte value, int count) + { + AssertOffsetAndLength(offset, sizeof(byte) * count); + for (var i = 0; i < count; ++i) + _buffer[offset + i] = value; + } + // this method exists in order to conform with Java ByteBuffer standards public void Put(int offset, byte value) { diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs index 5230b32f..7d211588 100644 --- a/net/FlatBuffers/FlatBufferBuilder.cs +++ b/net/FlatBuffers/FlatBufferBuilder.cs @@ -69,10 +69,7 @@ namespace FlatBuffers public void Pad(int size) { - for (var i = 0; i < size; i++) - { - _bb.PutByte(--_space, 0); - } + _bb.PutByte(_space -= size, 0, size); } // Doubles the size of the ByteBuffer, and copies the old data towards @@ -116,7 +113,8 @@ namespace FlatBuffers _space += (int)_bb.Length - oldBufSize; } - Pad(alignSize); + if (alignSize > 0) + Pad(alignSize); } public void PutBool(bool x) |