Skip to content

Commit

Permalink
Final tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescourtney committed Nov 28, 2022
1 parent 208a7f5 commit 2bf74ca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Serializers/FlatSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ public FlatSharp(Func<int, TSerialize> testData, Action<BookShelfFlatSharp, int,
[MethodImpl(MethodImplOptions.NoInlining)]
protected override void Serialize(TSerialize obj, Stream stream)
{
this.TranslateObject((BookShelf)(object)obj);

MemoryStream ms = (MemoryStream)stream;

this.TranslateObject((BookShelf)(object)obj, ms);

var serializer = BookShelfFlatSharp.Serializer;
var shelf = this.fsShelf;

// Expand size if necessary.
ms.SetLength(serializer.GetMaxSize(shelf));

// Write to the underlying buffer.
int bytesWritten = serializer.Write(ms.GetBuffer(), shelf);

Expand All @@ -50,7 +47,7 @@ protected override void Serialize(TSerialize obj, Stream stream)
/// Note: since this translation process is expensive (and not part of the benchmark),
/// only do this once per unique BookShelf.
/// </summary>
private void TranslateObject(BookShelf obj)
private void TranslateObject(BookShelf obj, MemoryStream stream)
{
if (this.knownBookshelf == obj)
{
Expand All @@ -70,6 +67,9 @@ private void TranslateObject(BookShelf obj)

bookshelf.Books = fsBooks;
this.fsShelf = bookshelf;

// Expand size if necessary.
stream.SetLength(BookShelfFlatSharp.Serializer.GetMaxSize(bookshelf));
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down

0 comments on commit 2bf74ca

Please sign in to comment.