Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ to fill the passed in ETW data descriptor.
else if (data is Guid)
{
dataDescriptor->Size = (uint)sizeof(Guid);
Guid* guidptr = (Guid*)dataBuffer;
*guidptr = (Guid)data;
void* guidptr = dataBuffer;
((Guid)data).TryWriteBytes(new Span<byte>(ref *(byte*)guidptr, sizeof(Guid)));
dataDescriptor->Ptr = (ulong)guidptr;
}
else if (data is decimal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,8 +1902,8 @@ private static unsafe void DecodeObjects(object?[] decodedObjects, Type[] parame
}
else if (dataType == typeof(Guid))
{
Debug.Assert(size == 16);
decoded = *(Guid*)dataPointer;
Debug.Assert(size == sizeof(Guid));
decoded = new Guid(new ReadOnlySpan<byte>(ref *(byte*)dataPointer, sizeof(Guid)));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,18 @@ public double ReadDouble()

public Guid ReadGuid()
{
const int size = 16;
byte* ptr = GetCurrentPointerAndAdvance(size);
byte* ptr = GetCurrentPointerAndAdvance(sizeof(Guid));

#if NET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that this change is worth it. It is adding ifdef, it is not reducing amount of unsafe code, and it may make the code a bit slower.

return new Guid(MemoryMarshal.CreateReadOnlySpan(ref *ptr, sizeof(Guid)));
#else
if (BitConverter.IsLittleEndian)
{
return *(Guid*)ptr;
}
else
{
Debug.Assert(sizeof(Guid) == 16);
unchecked
{
return new Guid(
Expand All @@ -328,6 +332,7 @@ public Guid ReadGuid()
ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
}
}
#endif
}

/// <summary>
Expand Down
Loading