Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary unsafe method uses #114

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
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
26 changes: 4 additions & 22 deletions src/ZLogger/Internal/MagicalBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ public T Read<T>(int offset)
public ReadOnlySpan<byte> ReadRawEnumValue(Type type, int offset)
{
var (_, size, _) = ReaderCache.GetEnumDictionaryAndValueSize(type);
#if NETSTANDARD2_0
return Shims.CreateReadOnlySpan(ref storage[offset], size);
#else
return MemoryMarshal.CreateReadOnlySpan(ref storage[offset], size);
#endif
return storage.AsSpan(offset, size);
}

public bool TryReadTo(Type type, int offset, int alignment, string? format, ref Utf8StringWriter<IBufferWriter<byte>> handler)
Expand Down Expand Up @@ -141,12 +137,7 @@ public bool TryReadTo(Type type, int offset, int alignment, string? format, ref
if (type.IsEnum)
{
var (dict, size, converter) = ReaderCache.GetEnumDictionaryAndValueSize(type);
var rawValue =
#if NETSTANDARD2_0
Shims.CreateReadOnlySpan(ref storage[offset], size);
#else
MemoryMarshal.CreateReadOnlySpan(ref storage[offset], size);
#endif
var rawValue = storage.AsSpan(offset, size);
var name = dict.GetUtf8Name(rawValue);
if (name == null)
{
Expand Down Expand Up @@ -244,11 +235,7 @@ public bool TryReadTo(Type type, int offset, int alignment, string? format, ref
if (type.IsEnum)
{
var (dict, size, converter) = ReaderCache.GetEnumDictionaryAndValueSize(type);
#if NETSTANDARD2_0
var rawValue = Shims.CreateReadOnlySpan(ref storage[offset], size);
#else
var rawValue = MemoryMarshal.CreateReadOnlySpan(ref storage[offset], size);
#endif
var rawValue = storage.AsSpan(offset, size);
var name = dict.GetStringName(rawValue);
if (name == null)
{
Expand Down Expand Up @@ -348,12 +335,7 @@ public bool TryReadTo(Type type, int offset, Utf8JsonWriter jsonWriter)
if (type.IsEnum)
{
var (dict, size, converter) = ReaderCache.GetEnumDictionaryAndValueSize(type);
var rawValue =
#if NETSTANDARD2_0
Shims.CreateReadOnlySpan(ref storage[offset], size);
#else
MemoryMarshal.CreateReadOnlySpan(ref storage[offset], size);
#endif
var rawValue = storage.AsSpan(offset, size);
var name = dict.GetJsonEncodedName(rawValue);
if (name == null)
{
Expand Down
Loading