diff --git a/GameFrameX.Foundation.Extensions/SpanExtensions.cs b/GameFrameX.Foundation.Extensions/SpanExtensions.cs index 86e372f..4948bec 100644 --- a/GameFrameX.Foundation.Extensions/SpanExtensions.cs +++ b/GameFrameX.Foundation.Extensions/SpanExtensions.cs @@ -135,7 +135,7 @@ public static void WriteBoolValue(this Span buffer, bool value, ref int of /// 读写操作的起始位置,写入后会自动增加相应字节数 / The starting position for read/write, automatically increments by the corresponding number of bytes after writing. /// 为 null 时抛出 / Thrown when is null. /// 为负数或超出缓冲区边界时抛出 / Thrown when is negative or exceeds buffer bounds. - public static unsafe void WriteBytesWithoutLength(this Span buffer, byte[] value, ref int offset) + public static void WriteBytesWithoutLength(this Span buffer, byte[] value, ref int offset) { ArgumentNullException.ThrowIfNull(value); ArgumentOutOfRangeException.ThrowIfNegative(offset, nameof(offset)); @@ -145,11 +145,8 @@ public static unsafe void WriteBytesWithoutLength(this Span buffer, byte[] throw new ArgumentOutOfRangeException(nameof(offset), LocalizationService.GetString(LocalizationKeys.Exceptions.OffsetOutsideBufferBounds, offset, value.Length, buffer.Length)); } - fixed (byte* ptr = buffer, valPtr = value) - { - Buffer.MemoryCopy(valPtr, ptr + offset, value.Length, value.Length); - offset += value.Length; - } + value.AsSpan().CopyTo(buffer[offset..]); + offset += value.Length; } ///