Skip to content

Commit c97b4eb

Browse files
committed
Forgot to optimize guid with span
1 parent 8835558 commit c97b4eb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/FirebirdSql.Data.FirebirdClient/Client/Managed/XdrReaderWriter.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,7 @@ public Guid ReadGuid(int sqlType)
299299
{
300300
Span<byte> buf = stackalloc byte[16];
301301
ReadOpaque(buf, 16);
302-
var rented = ArrayPool<byte>.Shared.Rent(16);
303-
try
304-
{
305-
buf.CopyTo(rented);
306-
return TypeDecoder.DecodeGuid(rented);
307-
}
308-
finally
309-
{
310-
ArrayPool<byte>.Shared.Return(rented);
311-
}
302+
return TypeDecoder.DecodeGuidSpan(buf);
312303
}
313304
}
314305
public async ValueTask<Guid> ReadGuidAsync(int sqlType, CancellationToken cancellationToken = default)

src/FirebirdSql.Data.FirebirdClient/Common/TypeDecoder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public static Guid DecodeGuid(byte[] value)
111111
return new Guid(a, b, c, value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15]);
112112
}
113113

114+
public static Guid DecodeGuidSpan(Span<byte> value)
115+
{
116+
var a = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(value[..4]));
117+
var b = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(value[4..6]));
118+
var c = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(value[6..8]));
119+
return new Guid(a, b, c, value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15]);
120+
}
121+
114122
public static int DecodeInt32(byte[] value)
115123
{
116124
return IPAddress.HostToNetworkOrder(BitConverter.ToInt32(value, 0));

0 commit comments

Comments
 (0)