Skip to content

Commit e8a661c

Browse files
committed
Using Approach A (unsafe block) to avoid allocations for FastBufferReader
1 parent 7326a83 commit e8a661c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkPrefabHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ internal FastBufferReader GetInstantiationDataReader(uint objectHash, FastBuffer
296296

297297
fastBufferReader.ReadValueSafe(out int dataSize);
298298
int dataStartPos = fastBufferReader.Position;
299-
var result = new FastBufferReader(fastBufferReader, Collections.Allocator.Temp, dataSize, dataStartPos);
300-
fastBufferReader.Seek(dataStartPos + dataSize);
301-
return result;
299+
unsafe
300+
{
301+
byte* ptr = fastBufferReader.GetUnsafePtr() + dataStartPos;
302+
return new FastBufferReader(ptr, Collections.Allocator.None, dataSize);
303+
}
302304
}
303305

304306
/// <summary>

0 commit comments

Comments
 (0)