Commit b8187e5b authored by Oli Wilkinson's avatar Oli Wilkinson

Performance tweak to FlatBufferBuilder.CreateString method to remove the…

Performance tweak to FlatBufferBuilder.CreateString method to remove the unnecessary byte buffer allocation

(See https://github.com/google/flatbuffers/issues/55#issuecomment-164031718 for stats)
parent 42b48bd5
......@@ -277,11 +277,10 @@ namespace FlatBuffers
public StringOffset CreateString(string s)
{
NotNested();
byte[] utf8 = Encoding.UTF8.GetBytes(s);
AddByte((byte)0);
StartVector(1, utf8.Length, 1);
Buffer.BlockCopy(utf8, 0, _bb.Data, _space -= utf8.Length,
utf8.Length);
AddByte(0);
var utf8StringLen = Encoding.UTF8.GetByteCount(s);
StartVector(1, utf8StringLen, 1);
Encoding.UTF8.GetBytes(s, 0, s.Length, _bb.Data, _space -= utf8StringLen);
return new StringOffset(EndVector().Value);
}
......
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