Get the project to compile after updating to .NET 7

This commit is contained in:
Alex Barney 2022-11-15 18:53:22 -07:00
parent fe8699e8c4
commit ffc9a76fc6
95 changed files with 409 additions and 253 deletions

View file

@ -1 +1 @@
6.0.403
7.0.100

View file

@ -45,7 +45,7 @@ partial class Build : NukeBuild
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed";
AbsolutePath TempDirectory => RootDirectory / ".nuke" / "temp";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net6.0";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net7.0";
AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}";
AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}";
AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip";
@ -229,7 +229,7 @@ partial class Build : NukeBuild
DotNetPublish(s => publishSettings
.SetProject(HactoolnetProject)
.SetFramework("net6.0")
.SetFramework("net7.0")
.SetOutput(CliCoreDir)
.SetNoBuild(true)
.SetProperties(VersionProps));
@ -279,7 +279,7 @@ partial class Build : NukeBuild
.EnableNoBuild()
.SetConfiguration(Configuration);
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net6.0");
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net7.0");
DotNetTest(s => settings);
});
@ -596,7 +596,7 @@ partial class Build : NukeBuild
SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray());
// Avoid having multiple signed versions of the same file
File.Copy(nupkgDir / "lib" / "net6.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
File.Copy(nupkgDir / "lib" / "net7.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList, CommitTime);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir, CommitTime);

View file

@ -3,7 +3,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Nuke.Common;
namespace LibHacBuild.CodeGen;

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild.CodeGen</RootNamespace>
<IsPackable>False</IsPackable>

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild</RootNamespace>
<IsPackable>False</IsPackable>

View file

@ -2,6 +2,5 @@
<configuration>
<packageSources>
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
</packageSources>
</configuration>

View file

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -43,6 +44,7 @@ public struct Uid : IEquatable<Uid>, IComparable<Uid>, IComparable
public void ToBytes(Span<byte> output) => Id.ToBytes(output);
[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using LibHac.Common;
using LibHac.Common.FixedArrays;
@ -13,8 +14,8 @@ public struct EncryptedKeyBlob
public AesIv Counter;
public Array144<byte> Payload;
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros()
@ -41,8 +42,8 @@ public struct KeyBlob
public Array112<byte> Unused;
public AesKey Package1Key;
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros()

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -35,8 +36,8 @@ public struct Package1MetaData
public byte KeyGeneration;
public byte Version;
public U8Span BuildDate => new U8Span(_buildDate);
public ReadOnlySpan<byte> Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10);
[UnscopedRef] public U8Span BuildDate => new U8Span(_buildDate);
[UnscopedRef] public ReadOnlySpan<byte> Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10);
}
public struct Package1Stage1Footer

View file

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Util;
@ -22,7 +23,7 @@ public struct Buffer16
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
// Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -37,7 +38,7 @@ public struct Buffer16
return SpanHelpers.AsReadOnlyByteSpan(in value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T As<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() > (uint)Unsafe.SizeOf<Buffer16>())
@ -48,13 +49,13 @@ public struct Buffer16
return ref MemoryMarshal.GetReference(AsSpan<T>());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan<T>() where T : unmanaged
{
return SpanHelpers.AsSpan<Buffer16, T>(ref this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<T> AsReadOnlySpan<T>() where T : unmanaged
{
return SpanHelpers.AsReadOnlySpan<Buffer16, T>(in this);
@ -80,7 +81,7 @@ public struct Buffer32
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
// Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -95,7 +96,7 @@ public struct Buffer32
return SpanHelpers.AsReadOnlyByteSpan(in value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T As<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() > (uint)Unsafe.SizeOf<Buffer32>())
@ -106,13 +107,13 @@ public struct Buffer32
return ref MemoryMarshal.GetReference(AsSpan<T>());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan<T>() where T : unmanaged
{
return SpanHelpers.AsSpan<Buffer32, T>(ref this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<T> AsReadOnlySpan<T>() where T : unmanaged
{
return SpanHelpers.AsReadOnlySpan<Buffer32, T>(in this);

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -10,10 +11,10 @@ public struct Array1<T>
private T _0;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array1<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array1024<T>
private Array512<T> _0;
private Array512<T> _512;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -20,10 +21,10 @@ public struct Array11<T>
private T _9;
private T _10;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array11<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array112<T>
private Array80<T> _0;
private Array32<T> _80;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -21,10 +22,10 @@ public struct Array12<T>
private T _10;
private T _11;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array12<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array128<T>
private Array64<T> _0;
private Array64<T> _64;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array14<T>
private Array8<T> _0;
private Array6<T> _8;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array144<T>
private Array128<T> _0;
private Array16<T> _128;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array15<T>
private Array8<T> _0;
private Array7<T> _8;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array16<T>
private Array8<T> _0;
private Array8<T> _8;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array16384<T>
private Array8192<T> _0;
private Array8192<T> _8192;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array18<T>
private Array16<T> _0;
private Array2<T> _16;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array192<T>
private Array128<T> _0;
private Array64<T> _128;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -11,10 +12,10 @@ public struct Array2<T>
private T _0;
private T _1;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array2<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array20<T>
private Array16<T> _0;
private Array4<T> _16;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array2048<T>
private Array1024<T> _0;
private Array1024<T> _1024;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array24<T>
private Array16<T> _0;
private Array8<T> _16;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array256<T>
private Array128<T> _0;
private Array128<T> _128;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -13,14 +14,16 @@ public struct Array26<T>
private Array8<T> _16;
private Array2<T> _24;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -14,14 +15,16 @@ public struct Array27<T>
private Array2<T> _24;
private T _26;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -13,14 +14,16 @@ public struct Array28<T>
private Array8<T> _16;
private Array4<T> _24;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -12,10 +13,10 @@ public struct Array3<T>
private T _1;
private T _2;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array3<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -15,14 +16,16 @@ public struct Array3000<T>
private Array128<T> _2816;
private Array56<T> _2944;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array32<T>
private Array16<T> _0;
private Array16<T> _16;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -14,14 +15,16 @@ public struct Array356<T>
private Array32<T> _320;
private Array4<T> _352;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array36<T>
private Array32<T> _0;
private Array4<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array37<T>
private Array32<T> _0;
private Array5<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array38<T>
private Array32<T> _0;
private Array6<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -13,10 +14,10 @@ public struct Array4<T>
private T _2;
private T _3;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array4<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -13,14 +14,16 @@ public struct Array400<T>
private Array128<T> _256;
private Array16<T> _384;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array4096<T>
private Array2048<T> _0;
private Array2048<T> _2048;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -14,14 +15,16 @@ public struct Array452<T>
private Array64<T> _384;
private Array4<T> _448;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -14,14 +15,16 @@ public struct Array464<T>
private Array64<T> _384;
private Array16<T> _448;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array48<T>
private Array32<T> _0;
private Array16<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -14,10 +15,10 @@ public struct Array5<T>
private T _3;
private T _4;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array5<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array512<T>
private Array256<T> _0;
private Array256<T> _256;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array56<T>
private Array32<T> _0;
private Array24<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -15,10 +16,10 @@ public struct Array6<T>
private T _4;
private T _5;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array6<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -13,14 +14,16 @@ public struct Array60<T>
private Array16<T> _32;
private Array12<T> _48;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array64<T>
private Array32<T> _0;
private Array32<T> _32;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array65<T>
private Array64<T> _0;
private T _64;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array68<T>
private Array64<T> _0;
private Array4<T> _64;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -16,10 +17,10 @@ public struct Array7<T>
private T _5;
private T _6;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array7<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array768<T>
private Array512<T> _0;
private Array256<T> _512;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -13,14 +14,16 @@ public struct Array769<T>
private Array256<T> _512;
private Array1<T> _768;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace LibHac.Common.FixedArrays;
@ -17,10 +18,10 @@ public struct Array8<T>
private T _6;
private T _7;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array8<T> value) => value.ItemsRo;

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array80<T>
private Array64<T> _0;
private Array16<T> _64;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array8192<T>
private Array4096<T> _0;
private Array4096<T> _4096;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -12,14 +13,16 @@ public struct Array96<T>
private Array80<T> _0;
private Array16<T> _80;
public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];
[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}
[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Util;
@ -67,6 +68,7 @@ public struct Id128 : IEquatable<Id128>, IComparable<Id128>, IComparable
longs[1] = Low;
}
[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);

View file

@ -57,7 +57,7 @@ public static unsafe class InteropWin32
public long LastWriteTime => (long)((ulong)_lastWriteHigh << 32 | _lastWriteLow);
public long FileSize => (long)_fileSizeHigh << 32 | _fileSizeLow;
public Span<char> FileName => MemoryMarshal.CreateSpan(ref _fileName[0], 260);
public Span<char> AlternateFileName => MemoryMarshal.CreateSpan(ref _alternateFileName[0], 14);
public Span<char> FileName => SpanHelpers.CreateSpan(ref _fileName[0], 260);
public Span<char> AlternateFileName => SpanHelpers.CreateSpan(ref _alternateFileName[0], 14);
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Util;
@ -10,7 +11,7 @@ public struct Key128 : IEquatable<Key128>
private readonly ulong _dummy1;
private readonly ulong _dummy2;
public Span<byte> Value => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public Span<byte> Value => SpanHelpers.AsByteSpan(ref this);
public Key128(ReadOnlySpan<byte> bytes)
{

View file

@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace LibHac.Common;
@ -14,10 +12,7 @@ namespace LibHac.Common;
/// <typeparam name="T">The type of value to reference.</typeparam>
public readonly ref struct Ref<T>
{
/// <summary>
/// The 1-length <see cref="Span{T}"/> instance used to track the target <typeparamref name="T"/> value.
/// </summary>
private readonly Span<T> _span;
private readonly ref T _ref;
/// <summary>
/// Initializes a new instance of the <see cref="Ref{T}"/> struct.
@ -26,7 +21,7 @@ public readonly ref struct Ref<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Ref(ref T value)
{
_span = MemoryMarshal.CreateSpan(ref value, 1);
_ref = ref value;
}
/// <summary>
@ -40,11 +35,7 @@ public readonly ref struct Ref<T>
/// <summary>
/// Gets the <typeparamref name="T"/> reference represented by the current <see cref="Ref{T}"/> instance.
/// </summary>
public ref T Value
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref MemoryMarshal.GetReference(_span);
}
public ref T Value => ref _ref;
/// <summary>
/// Returns a value that indicates whether the current <see cref="Ref{T}"/> is <see langword="null"/>.
@ -74,10 +65,7 @@ public readonly ref struct Ref<T>
/// <typeparam name="T">The type of value to reference.</typeparam>
public readonly ref struct ReadOnlyRef<T>
{
/// <summary>
/// The 1-length <see cref="ReadOnlySpan{T}"/> instance used to track the target <typeparamref name="T"/> value.
/// </summary>
private readonly ReadOnlySpan<T> _span;
private readonly ref readonly T _ref;
/// <summary>
/// Initializes a new instance of the <see cref="Ref{T}"/> struct.
@ -86,7 +74,7 @@ public readonly ref struct ReadOnlyRef<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlyRef(in T value)
{
_span = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in value), 1);
_ref = ref value;
}
/// <summary>
@ -103,7 +91,7 @@ public readonly ref struct ReadOnlyRef<T>
public ref readonly T Value
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref MemoryMarshal.GetReference(_span);
get => ref _ref;
}
/// <summary>

View file

@ -42,7 +42,7 @@ public static class SpanHelpers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<T> AsSpan<T>(ref T reference) where T : unmanaged
{
return CreateSpan(ref reference, 1);
return new Span<T>(ref reference);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -68,7 +68,7 @@ public static class SpanHelpers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<T> AsReadOnlySpan<T>(in T reference) where T : unmanaged
{
return CreateReadOnlySpan(in reference, 1);
return new ReadOnlySpan<T>(in reference);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -16,10 +17,10 @@ public struct AesKey
[FieldOffset(0)] private byte _byte;
[FieldOffset(0)] private ulong _ulong;
public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[UnscopedRef] public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
[UnscopedRef] public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
[UnscopedRef] public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
[UnscopedRef] public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0;
@ -31,7 +32,7 @@ public struct AesKey
public readonly override string ToString() => DataRo.ToHexString();
#if DEBUG
[FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
[FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
#endif
}
@ -46,12 +47,12 @@ public struct AesXtsKey
[FieldOffset(0)] public AesKey DataKey;
[FieldOffset(0x10)] public AesKey TweakKey;
public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[UnscopedRef] public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
[UnscopedRef] public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
[UnscopedRef] public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
[UnscopedRef] public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
public Span<AesKey> SubKeys => SpanHelpers.CreateSpan(ref DataKey, Size / Unsafe.SizeOf<AesKey>());
[UnscopedRef] public Span<AesKey> SubKeys => SpanHelpers.CreateSpan(ref DataKey, Size / Unsafe.SizeOf<AesKey>());
public static implicit operator Span<byte>(in AesXtsKey value) => Unsafe.AsRef(in value).Data;
public static implicit operator ReadOnlySpan<byte>(in AesXtsKey value) => value.DataRo;
@ -70,10 +71,10 @@ public struct AesIv
[FieldOffset(0)] private byte _byte;
[FieldOffset(0)] private ulong _ulong;
public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[UnscopedRef] public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
[UnscopedRef] public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
[UnscopedRef] public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
[UnscopedRef] public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0;
@ -84,7 +85,7 @@ public struct AesIv
public readonly override string ToString() => DataRo.ToHexString();
#if DEBUG
[FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
[FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
#endif
}
@ -96,10 +97,10 @@ public struct AesCmac
[FieldOffset(0)] private byte _byte;
[FieldOffset(0)] private ulong _ulong;
public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[UnscopedRef] public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
[UnscopedRef] public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);
[UnscopedRef] public Span<ulong> Data64 => SpanHelpers.CreateSpan(ref _ulong, Size / sizeof(ulong));
[UnscopedRef] public readonly ReadOnlySpan<ulong> DataRo64 => SpanHelpers.CreateReadOnlySpan(in _ulong, Size / sizeof(ulong));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros() => (DataRo64[0] | DataRo64[1]) == 0;
@ -110,7 +111,7 @@ public struct AesCmac
public readonly override string ToString() => DataRo.ToHexString();
#if DEBUG
[FieldOffset(8)] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
[FieldOffset(8)][DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _dummy1;
#endif
}

View file

@ -1,6 +1,7 @@
using System;
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Unicode;
@ -163,6 +164,7 @@ namespace LibHac.Fs.Impl
{
private Buffer32 _buffer;
[UnscopedRef]
private ReadOnlySpan<byte> ToValueString(int value)
{
bool success = Utf8Formatter.TryFormat(value, _buffer.Bytes, out int length);
@ -173,6 +175,7 @@ namespace LibHac.Fs.Impl
return _buffer.Bytes;
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(Priority value)
{
switch (value)
@ -184,6 +187,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(PriorityRaw value)
{
switch (value)
@ -196,6 +200,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(ImageDirectoryId value)
{
switch (value)
@ -206,6 +211,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(ContentStorageId value)
{
switch (value)
@ -217,6 +223,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(GameCardPartition value)
{
switch (value)
@ -229,6 +236,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(SaveDataSpaceId value)
{
switch (value)
@ -241,6 +249,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(SaveDataFormatType value)
{
switch (value)
@ -251,6 +260,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(ContentType value)
{
switch (value)
@ -264,6 +274,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(BisPartitionId value)
{
switch (value)
@ -289,6 +300,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(DirectoryEntryType value)
{
switch (value)
@ -299,6 +311,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(MountHostOption value)
{
switch (value.Flags)
@ -308,6 +321,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(MemoryCapacity value)
{
switch (value)
@ -322,6 +336,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(SelSec value)
{
switch (value)
@ -332,6 +347,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(KekIndex value)
{
switch (value)
@ -342,6 +358,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(AccessControl1ClockRate value)
{
switch (value)
@ -352,6 +369,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(FwVersion value)
{
switch (value)
@ -366,6 +384,7 @@ namespace LibHac.Fs.Impl
}
}
[UnscopedRef]
public ReadOnlySpan<byte> ToString(GameCardCompatibilityType value)
{
switch (value)

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using LibHac.Common;
using LibHac.Diag;
using static LibHac.Fs.StringTraits;
@ -16,21 +17,19 @@ public ref struct DirectoryPathParser
private Span<byte> _buffer;
private byte _replacedChar;
private int _position;
// Todo: Make private so we can use the GetCurrentPath method once lifetime tracking is better
public Path CurrentPath;
private Path _currentPath;
public DirectoryPathParser()
{
_buffer = Span<byte>.Empty;
_replacedChar = 0;
_position = 0;
CurrentPath = new Path();
_currentPath = new Path();
}
public void Dispose()
{
CurrentPath.Dispose();
_currentPath.Dispose();
}
/// <summary>
@ -40,7 +39,7 @@ public ref struct DirectoryPathParser
/// </summary>
/// <param name="path">The <see cref="Path"/> to iterate. Must have an allocated write buffer.</param>
/// <returns>The <see cref="Result"/> of the operation.</returns>
public Result Initialize(ref Path path)
public Result Initialize(scoped ref Path path)
{
Span<byte> pathBuffer = path.GetWriteBufferLength() != 0 ? path.GetWriteBuffer() : Span<byte>.Empty;
@ -49,7 +48,7 @@ public ref struct DirectoryPathParser
if (windowsSkipLength != 0)
{
Result res = CurrentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1);
Result res = _currentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1);
if (res.IsFailure()) return res.Miss();
_buffer = _buffer.Slice(1);
@ -60,7 +59,7 @@ public ref struct DirectoryPathParser
if (!initialPath.IsEmpty)
{
Result res = CurrentPath.InitializeWithNormalization(initialPath);
Result res = _currentPath.InitializeWithNormalization(initialPath);
if (res.IsFailure()) return res.Miss();
}
}
@ -68,11 +67,11 @@ public ref struct DirectoryPathParser
return Result.Success;
}
// Todo: Return reference when escape semantics are better
//public ref readonly Path GetCurrentPath()
//{
// return ref CurrentPath;
//}
[UnscopedRef]
public ref readonly Path GetCurrentPath()
{
return ref _currentPath;
}
public Result ReadNext(out bool isFinished)
{
@ -86,7 +85,7 @@ public ref struct DirectoryPathParser
return Result.Success;
}
return CurrentPath.AppendChild(nextEntry);
return _currentPath.AppendChild(nextEntry);
}
private Span<byte> ReadNextImpl()

View file

@ -46,7 +46,7 @@ public static class PathExtensions
/// <param name="path">The read-only reference to reinterpret.</param>
/// <returns>A reference to the given <see cref="Path"/>.</returns>
// ReSharper disable once EntityNameCapturedOnly.Global
public static ref Path Ref(this in Path path)
public static ref Path Ref(this scoped in Path path)
{
Ldarg(nameof(path));
Ret();
@ -122,7 +122,7 @@ public ref struct Path
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotNormalized"/>: The <c>IsNormalized</c> flag of
/// <paramref name="path"/> is not <see langword="true"/>.</returns>
public Result Initialize(in Path path)
public Result Initialize(scoped in Path path)
{
if (!path._isNormalized)
return ResultFs.NotNormalized.Log();
@ -249,17 +249,17 @@ public ref struct Path
/// <param name="value">The string to compare to this <see cref="Path"/>.</param>
/// <param name="length">The maximum number of characters to compare.</param>
/// <returns><see langword="true"/> if the strings are the same; otherwise <see langword="false"/>.</returns>
public readonly bool IsMatchHead(ReadOnlySpan<byte> value, int length)
public readonly bool IsMatchHead(scoped ReadOnlySpan<byte> value, int length)
{
return StringUtils.Compare(GetString(), value, length) == 0;
}
public static bool operator !=(in Path left, in Path right)
public static bool operator !=(scoped in Path left, scoped in Path right)
{
return !(left == right);
}
public static bool operator !=(in Path left, ReadOnlySpan<byte> right)
public static bool operator !=(scoped in Path left, scoped ReadOnlySpan<byte> right)
{
return !(left == right);
}
@ -397,7 +397,7 @@ public ref struct Path
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotNormalized"/>: The <c>IsNormalized</c> flag of
/// <paramref name="other"/> is not <see langword="true"/>.</returns>
public Result Initialize(in Path other)
public Result Initialize(scoped in Path other)
{
if (!other._isNormalized)
return ResultFs.NotNormalized.Log();
@ -424,7 +424,7 @@ public ref struct Path
/// because <see cref="Stored"/> paths are always normalized upon initialization.</remarks>
/// <param name="other">The <see cref="Stored"/> path used to initialize this <see cref="Path"/>.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result Initialize(in Stored other)
public Result Initialize(scoped in Stored other)
{
int otherLength = other.GetLength();
@ -449,7 +449,7 @@ public ref struct Path
/// <param name="path">The buffer containing the path to use.</param>
/// <param name="length">The length of the provided path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
private Result InitializeImpl(ReadOnlySpan<byte> path, int length)
private Result InitializeImpl(scoped ReadOnlySpan<byte> path, int length)
{
if (length == 0 || path.At(0) == NullTerminator)
{
@ -476,7 +476,7 @@ public ref struct Path
/// This function will always set the <c>IsNormalized</c> flag to <see langword="false"/>.</remarks>
/// <param name="path">The buffer containing the path to use.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result Initialize(ReadOnlySpan<byte> path)
public Result Initialize(scoped ReadOnlySpan<byte> path)
{
Result res = InitializeImpl(path, StringUtils.GetLength(path));
if (res.IsFailure()) return res.Miss();
@ -661,7 +661,7 @@ public ref struct Path
/// </remarks>
/// <param name="path">The buffer containing the path to use.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result InitializeWithReplaceUnc(ReadOnlySpan<byte> path)
public Result InitializeWithReplaceUnc(scoped ReadOnlySpan<byte> path)
{
Result res = InitializeImpl(path, StringUtils.GetLength(path));
if (res.IsFailure()) return res.Miss();
@ -720,7 +720,7 @@ public ref struct Path
/// <param name="parent">The buffer containing the path to insert.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotImplemented"/>: The path provided in <paramref name="parent"/> is a Windows path.</returns>
public Result InsertParent(ReadOnlySpan<byte> parent)
public Result InsertParent(scoped ReadOnlySpan<byte> parent)
{
if (parent.Length == 0 || parent[0] == NullTerminator)
return Result.Success;
@ -832,7 +832,7 @@ public ref struct Path
/// <param name="parent">The <see cref="Path"/> to insert.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotImplemented"/>: The path provided in <paramref name="parent"/> is a Windows path.</returns>
public Result InsertParent(in Path parent)
public Result InsertParent(scoped in Path parent)
{
return InsertParent(parent.GetString());
}
@ -845,7 +845,7 @@ public ref struct Path
/// path is not normalized yet the <c>IsNormalized</c> flag is still <see langword="true"/>.</remarks>
/// <param name="child">The buffer containing the child path to append to the current path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result AppendChild(ReadOnlySpan<byte> child)
public Result AppendChild(scoped ReadOnlySpan<byte> child)
{
ReadOnlySpan<byte> trimmedChild = child;
@ -925,7 +925,7 @@ public ref struct Path
/// path is not normalized yet the <c>IsNormalized</c> flag is still <see langword="true"/>.</remarks>
/// <param name="child">The child <see cref="Path"/> to append to the current path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result AppendChild(in Path child)
public Result AppendChild(scoped in Path child)
{
return AppendChild(child.GetString());
}
@ -941,7 +941,7 @@ public ref struct Path
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotNormalized"/>: The <c>IsNormalized</c> flag of either
/// <paramref name="path1"/> or <paramref name="path2"/> is not <see langword="true"/>.</returns>
public Result Combine(in Path path1, in Path path2)
public Result Combine(scoped in Path path1, scoped in Path path2)
{
int path1Length = path1.GetLength();
int path2Length = path2.GetLength();
@ -977,7 +977,7 @@ public ref struct Path
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.NotNormalized"/>: The <c>IsNormalized</c> flag of
/// <paramref name="path1"/> is not <see langword="true"/>.</returns>
public Result Combine(in Path path1, ReadOnlySpan<byte> path2)
public Result Combine(scoped in Path path1, scoped ReadOnlySpan<byte> path2)
{
int path1Length = path1.GetLength();
int path2Length = StringUtils.GetLength(path2);
@ -1002,7 +1002,7 @@ public ref struct Path
/// <param name="path1">The first path to combine.</param>
/// <param name="path2">The second path to combine.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.</returns>
public Result Combine(ReadOnlySpan<byte> path1, in Path path2)
public Result Combine(scoped ReadOnlySpan<byte> path1, scoped in Path path2)
{
int path1Length = StringUtils.GetLength(path1);
int path2Length = path2.GetLength();
@ -1167,7 +1167,7 @@ public static class PathFunctions
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidCharacter"/>: The path contains an invalid character.<br/>
/// <see cref="ResultFs.InvalidPathFormat"/>: The path is in an invalid format or is not normalized.</returns>
public static Result SetUpFixedPath(ref Path path, ReadOnlySpan<byte> pathBuffer)
public static Result SetUpFixedPath(scoped ref Path path, ReadOnlySpan<byte> pathBuffer)
{
Result res = PathNormalizer.IsNormalized(out bool isNormalized, out _, pathBuffer);
if (res.IsFailure()) return res.Miss();
@ -1192,7 +1192,7 @@ public static class PathFunctions
/// <param name="entryName">The first entry in the generated path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidArgument"/>: <paramref name="pathBuffer"/> was too small to contain the built path.</returns>
internal static Result SetUpFixedPathSingleEntry(ref Path path, Span<byte> pathBuffer,
internal static Result SetUpFixedPathSingleEntry(scoped ref Path path, Span<byte> pathBuffer,
ReadOnlySpan<byte> entryName)
{
var sb = new U8StringBuilder(pathBuffer);
@ -1214,8 +1214,8 @@ public static class PathFunctions
/// <param name="entryName2">The second entry in the generated path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidArgument"/>: <paramref name="pathBuffer"/> was too small to contain the built path.</returns>
internal static Result SetUpFixedPathDoubleEntry(ref Path path, Span<byte> pathBuffer,
ReadOnlySpan<byte> entryName1, ReadOnlySpan<byte> entryName2)
internal static Result SetUpFixedPathDoubleEntry(scoped ref Path path, Span<byte> pathBuffer,
scoped ReadOnlySpan<byte> entryName1, scoped ReadOnlySpan<byte> entryName2)
{
var sb = new U8StringBuilder(pathBuffer);
sb.Append((byte)'/').Append(entryName1)
@ -1236,7 +1236,7 @@ public static class PathFunctions
/// <param name="saveDataId">The save data ID to insert into the path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidArgument"/>: <paramref name="pathBuffer"/> was too small to contain the built path.</returns>
internal static Result SetUpFixedPathSaveId(ref Path path, Span<byte> pathBuffer, ulong saveDataId)
internal static Result SetUpFixedPathSaveId(scoped ref Path path, Span<byte> pathBuffer, ulong saveDataId)
{
var sb = new U8StringBuilder(pathBuffer);
sb.Append((byte)'/').AppendFormat(saveDataId, 'x', 16);
@ -1256,7 +1256,7 @@ public static class PathFunctions
/// <param name="metaType">The <see cref="SaveDataMetaType"/> to insert into the path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidArgument"/>: <paramref name="pathBuffer"/> was too small to contain the built path.</returns>
internal static Result SetUpFixedPathSaveMetaName(ref Path path, Span<byte> pathBuffer, uint metaType)
internal static Result SetUpFixedPathSaveMetaName(scoped ref Path path, Span<byte> pathBuffer, uint metaType)
{
ReadOnlySpan<byte> metaExtension = new[] { (byte)'.', (byte)'m', (byte)'e', (byte)'t', (byte)'a' }; // ".meta"
@ -1278,7 +1278,7 @@ public static class PathFunctions
/// <param name="saveDataId">The save data ID to insert into the path.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.InvalidArgument"/>: <paramref name="pathBuffer"/> was too small to contain the built path.</returns>
internal static Result SetUpFixedPathSaveMetaDir(ref Path path, Span<byte> pathBuffer, ulong saveDataId)
internal static Result SetUpFixedPathSaveMetaDir(scoped ref Path path, Span<byte> pathBuffer, ulong saveDataId)
{
ReadOnlySpan<byte> metaDirectoryName = new[]
{

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using LibHac.Common;
using LibHac.Common.FixedArrays;
using LibHac.FsSrv.Impl;
@ -122,8 +123,8 @@ public struct HashSalt
{
private Array32<byte> _value;
public Span<byte> Hash => _value.Items;
public readonly ReadOnlySpan<byte> HashRo => _value.ItemsRo;
[UnscopedRef] public Span<byte> Hash => _value.Items;
[UnscopedRef] public readonly ReadOnlySpan<byte> HashRo => _value.ItemsRo;
}
public struct SaveDataAttribute : IEquatable<SaveDataAttribute>, IComparable<SaveDataAttribute>

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using LibHac.Common;
using LibHac.Common.FixedArrays;
@ -7,7 +8,7 @@ namespace LibHac.Fs;
internal struct MountName
{
private Array16<byte> _nameArray;
public Span<byte> Name => _nameArray.Items;
[UnscopedRef] public Span<byte> Name => _nameArray.Items;
public override string ToString() => new U8Span(Name).ToString();
}

View file

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -43,6 +44,7 @@ public struct UserId : IEquatable<UserId>, IComparable<UserId>, IComparable
public void ToBytes(Span<byte> output) => Id.ToBytes(output);
[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);

View file

@ -40,7 +40,7 @@ public class FileSystemProxyCoreImpl
Result res = _baseFileSystemService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User);
if (res.IsFailure()) return res.Miss();
using var path = new Path();
using scoped var path = new Path();
res = PathFunctions.SetUpFixedPathSingleEntry(ref path.Ref(), pathBuffer.Items,
CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System));
if (res.IsFailure()) return res.Miss();
@ -54,7 +54,7 @@ public class FileSystemProxyCoreImpl
Result res = _baseFileSystemService.OpenSdCardProxyFileSystem(ref fileSystem.Ref());
if (res.IsFailure()) return res.Miss();
using var path = new Path();
using scoped var path = new Path();
res = PathFunctions.SetUpFixedPathDoubleEntry(ref path.Ref(), pathBuffer.Items,
CommonPaths.SdCardNintendoRootDirectoryName,
CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System));

View file

@ -46,7 +46,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
{
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
using var saveImageName = new Path();
using scoped var saveImageName = new Path();
Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();

View file

@ -127,7 +127,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
// Get the path of the save data
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
using var saveImageName = new Path();
using scoped var saveImageName = new Path();
res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();
@ -169,7 +169,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
{
// Create the save data directory on the host if needed.
Unsafe.SkipInit(out Array18<byte> saveDirectoryNameBuffer);
using var saveDirectoryName = new Path();
using scoped var saveDirectoryName = new Path();
res = PathFunctions.SetUpFixedPathSaveId(ref saveDirectoryName.Ref(), saveDirectoryNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();
@ -232,7 +232,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
{
Unsafe.SkipInit(out Array27<byte> saveDataMetaIdDirectoryNameBuffer);
using var saveDataMetaIdDirectoryName = new Path();
using scoped var saveDataMetaIdDirectoryName = new Path();
Result res = PathFunctions.SetUpFixedPathSaveMetaDir(ref saveDataMetaIdDirectoryName.Ref(),
saveDataMetaIdDirectoryNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();
@ -313,7 +313,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
Unsafe.SkipInit(out Array15<byte> saveDataMetaNameBuffer);
using var saveDataMetaName = new Path();
using scoped var saveDataMetaName = new Path();
res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items,
(uint)metaType);
if (res.IsFailure()) return res.Miss();
@ -333,7 +333,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
Unsafe.SkipInit(out Array15<byte> saveDataMetaNameBuffer);
using var saveDataMetaName = new Path();
using scoped var saveDataMetaName = new Path();
res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items,
(uint)metaType);
if (res.IsFailure()) return res.Miss();
@ -357,7 +357,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
using var fileSystem = new SharedRef<IFileSystem>();
using var saveDataMetaDirectoryName = new Path();
using scoped var saveDataMetaDirectoryName = new Path();
Result res = PathFunctions.SetUpFixedPath(ref saveDataMetaDirectoryName.Ref(), metaDirName);
if (res.IsFailure()) return res.Miss();
@ -365,7 +365,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
createIfMissing: false);
if (res.IsFailure()) return res.Miss();
using var saveDataIdDirectoryName = new Path();
using scoped var saveDataIdDirectoryName = new Path();
PathFunctions.SetUpFixedPathSaveId(ref saveDataIdDirectoryName.Ref(), saveDataIdDirectoryNameBuffer.Items,
saveDataId);
if (res.IsFailure()) return res.Miss();
@ -394,7 +394,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
Unsafe.SkipInit(out Array15<byte> saveDataMetaNameBuffer);
using var saveDataMetaName = new Path();
using scoped var saveDataMetaName = new Path();
res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items,
(uint)metaType);
if (res.IsFailure()) return res.Miss();
@ -422,7 +422,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
allowEmulatedSave: false);
if (res.IsFailure()) return res.Miss();
using var saveImageName = new Path();
using scoped var saveImageName = new Path();
res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();
@ -494,7 +494,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, false);
if (res.IsFailure()) return res.Miss();
using var saveImageName = new Path();
using scoped var saveImageName = new Path();
res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();
@ -648,7 +648,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
SaveDataSpaceId spaceId)
{
using var rootPath = new Path();
using scoped var rootPath = new Path();
return OpenSaveDataDirectoryFileSystem(ref outFileSystem, spaceId, in rootPath, allowEmulatedSave: true);
}
@ -671,7 +671,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
if (res.IsFailure()) return res.Miss();
}
using var path = new Path();
using scoped var path = new Path();
res = path.Initialize(in saveDataRootPath);
if (res.IsFailure()) return res.Miss();
@ -692,7 +692,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
return Result.Success;
}
using var saveDataAreaDirectoryName = new Path();
using scoped var saveDataAreaDirectoryName = new Path();
ReadOnlySpan<byte> saveDirName;
if (spaceId == SaveDataSpaceId.Temporary)
@ -762,12 +762,12 @@ public class SaveDataFileSystemServiceImpl : IDisposable
Unsafe.SkipInit(out Array64<byte> pathParentBuffer);
using var pathParent = new Path();
using scoped var pathParent = new Path();
res = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer.Items,
CommonPaths.SdCardNintendoRootDirectoryName);
if (res.IsFailure()) return res.Miss();
using var pathSdRoot = new Path();
using scoped var pathSdRoot = new Path();
res = pathSdRoot.Combine(in pathParent, in directoryPath);
if (res.IsFailure()) return res.Miss();

View file

@ -336,7 +336,7 @@ public class SaveDataFileStorageHolder
{
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
using var saveImageName = new Path();
using scoped var saveImageName = new Path();
Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId);
if (res.IsFailure()) return res.Miss();

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -15,7 +16,7 @@ public readonly struct FspPath
private readonly Array769<byte> _value;
public ReadOnlySpan<byte> Str => SpanHelpers.AsReadOnlyByteSpan(in _value);
[UnscopedRef] public ReadOnlySpan<byte> Str => SpanHelpers.AsReadOnlyByteSpan(in _value);
public static Result FromSpan(out FspPath fspPath, ReadOnlySpan<byte> path)
{

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.Common.FixedArrays;
@ -10,5 +11,5 @@ public readonly struct Path
{
private readonly Array769<byte> _value;
public ReadOnlySpan<byte> Str => SpanHelpers.AsReadOnlyByteSpan(in _value);
[UnscopedRef] public ReadOnlySpan<byte> Str => SpanHelpers.AsReadOnlyByteSpan(in _value);
}

View file

@ -133,7 +133,7 @@ public class AesCtrStorage : IStorage
int writeSize = useWorkBuffer ? Math.Max(pooledBuffer.GetSize(), remaining) : remaining;
Span<byte> writeBuffer = useWorkBuffer
? pooledBuffer.GetBuffer().Slice(0, writeSize)
: MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(source), source.Length).Slice(0, writeSize);
: SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(source), source.Length).Slice(0, writeSize);
// Encrypt the data, with temporarily increased priority.
using (new ScopedThreadPriorityChanger(1, ScopedThreadPriorityChanger.Mode.Relative))

View file

@ -235,7 +235,7 @@ public class AesXtsStorageExternal : IStorage
// const_cast the input buffer and encrypt in-place if it's a "device buffer".
Span<byte> encryptDest = useWorkBuffer
? pooledBuffer.GetBuffer().Slice(encryptOffset, currentSize)
: MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(encryptSource), encryptSource.Length);
: SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(encryptSource), encryptSource.Length);
res = _encryptFunction(encryptDest, _key[0], _key[1], counter, encryptSource);
if (res.IsFailure()) return res.Miss();

View file

@ -192,7 +192,7 @@ internal static class Utility
}
public static Result CopyDirectoryRecursively(IFileSystem destinationFileSystem, IFileSystem sourceFileSystem,
in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span<byte> workBuffer)
in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span<byte> workBuffer)
{
static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure)
{
@ -235,7 +235,7 @@ internal static class Utility
}
public static Result CopyDirectoryRecursively(IFileSystem fileSystem, in Path destinationPath,
in Path sourcePath, ref DirectoryEntry dirEntry, Span<byte> workBuffer)
in Path sourcePath, ref DirectoryEntry dirEntry, Span<byte> workBuffer)
{
var closure = new FsIterationTaskClosure();
closure.Buffer = workBuffer;
@ -333,7 +333,7 @@ internal static class Utility
do
{
// Check if the path exists
res = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.CurrentPath);
res = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.GetCurrentPath());
if (!res.IsSuccess())
{
// Something went wrong if we get a result other than PathNotFound
@ -341,12 +341,12 @@ internal static class Utility
return res;
// Create the directory
res = fileSystem.CreateDirectory(in parser.CurrentPath);
res = fileSystem.CreateDirectory(in parser.GetCurrentPath());
if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res))
return res;
// Check once more if the path exists
res = fileSystem.GetEntryType(out type, in parser.CurrentPath);
res = fileSystem.GetEntryType(out type, in parser.GetCurrentPath());
if (res.IsFailure()) return res.Miss();
}

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -50,8 +51,9 @@ public struct KipHeader
public Array32<uint> Capabilities;
[UnscopedRef]
public Span<SegmentHeader> Segments =>
SpanHelpers.CreateSpan(ref Unsafe.As<int, SegmentHeader>(ref TextMemoryOffset), SegmentCount);
SpanHelpers.CreateSpan(ref Unsafe.As<int, SegmentHeader>(ref TextMemoryOffset), SegmentCount);
public bool IsValid => Magic == Kip1Magic;

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -10,7 +11,7 @@ public struct BoundedString<TSize> where TSize : unmanaged
{
private TSize _string;
public Span<byte> Get() => SpanHelpers.AsByteSpan(ref _string);
[UnscopedRef] public Span<byte> Get() => SpanHelpers.AsByteSpan(ref _string);
public int GetLength() =>
StringUtils.GetLength(SpanHelpers.AsReadOnlyByteSpan(in _string), Unsafe.SizeOf<TSize>());

View file

@ -109,7 +109,7 @@ internal ref struct KeyValueArchiveBufferReader
return Result.Success;
}
public Result ReadKeyValue(Span<byte> keyBuffer, Span<byte> valueBuffer)
public Result ReadKeyValue(scoped Span<byte> keyBuffer, scoped Span<byte> valueBuffer)
{
// This should only be called after ReadEntryCount.
Assert.SdkNotEqual(_offset, 0);
@ -136,7 +136,7 @@ internal ref struct KeyValueArchiveBufferReader
return Result.Success;
}
private Result Peek(Span<byte> destBuffer)
private Result Peek(scoped Span<byte> destBuffer)
{
// Bounds check.
if (_offset + destBuffer.Length > _buffer.Length ||
@ -149,7 +149,7 @@ internal ref struct KeyValueArchiveBufferReader
return Result.Success;
}
private Result Read(Span<byte> destBuffer)
private Result Read(scoped Span<byte> destBuffer)
{
Result res = Peek(destBuffer);
if (res.IsFailure()) return res.Miss();
@ -170,7 +170,7 @@ internal ref struct KeyValueArchiveBufferWriter
_offset = 0;
}
private void Write(ReadOnlySpan<byte> source)
private void Write(scoped ReadOnlySpan<byte> source)
{
// Bounds check.
Abort.DoAbortUnless(_offset + source.Length <= _buffer.Length &&
@ -189,7 +189,7 @@ internal ref struct KeyValueArchiveBufferWriter
Write(SpanHelpers.AsByteSpan(ref header));
}
public void WriteEntry(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value)
public void WriteEntry(scoped ReadOnlySpan<byte> key, scoped ReadOnlySpan<byte> value)
{
// This should only be called after writing header.
Assert.SdkNotEqual(_offset, 0);

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<VersionPrefix>0.17.0</VersionPrefix>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -67,7 +67,7 @@ public class MetaLoader
return ResultLoader.InvalidMeta.Log();
}
npdm = GetNpdmFromBufferUnsafe(ref MemoryMarshal.GetArrayDataReference(_npdmBuffer));
npdm = GetNpdmFromBufferUnsafe(_npdmBuffer);
return Result.Success;
}
@ -98,9 +98,9 @@ public class MetaLoader
if (res.IsFailure()) return res.Miss();
// Set Npdm members.
npdm.Meta = new ReadOnlyRef<Meta>(in meta);
npdm.Acid = new ReadOnlyRef<AcidHeaderData>(in acid);
npdm.Aci = new ReadOnlyRef<AciHeader>(in aci);
npdm.Meta = ref meta;
npdm.Acid = ref acid;
npdm.Aci = ref aci;
npdm.FsAccessControlDescriptor = acidBuffer.Slice(acid.FsAccessControlOffset, acid.FsAccessControlSize);
npdm.ServiceAccessControlDescriptor = acidBuffer.Slice(acid.ServiceAccessControlOffset, acid.ServiceAccessControlSize);
@ -113,8 +113,10 @@ public class MetaLoader
return Result.Success;
}
private static Npdm GetNpdmFromBufferUnsafe(ref byte npdmBuffer)
private static Npdm GetNpdmFromBufferUnsafe(ReadOnlySpan<byte> npdmSpan)
{
ref byte npdmBuffer = ref MemoryMarshal.GetReference(npdmSpan);
var npdm = new Npdm();
ref Meta meta = ref Unsafe.As<byte, Meta>(ref npdmBuffer);
@ -122,17 +124,17 @@ public class MetaLoader
ref AciHeader aci = ref Unsafe.As<byte, AciHeader>(ref Unsafe.Add(ref npdmBuffer, meta.AciOffset));
// Set Npdm members.
npdm.Meta = new ReadOnlyRef<Meta>(in meta);
npdm.Acid = new ReadOnlyRef<AcidHeaderData>(in acid);
npdm.Aci = new ReadOnlyRef<AciHeader>(in aci);
npdm.Meta = ref meta;
npdm.Acid = ref acid;
npdm.Aci = ref aci;
npdm.FsAccessControlDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.FsAccessControlOffset), acid.FsAccessControlSize);
npdm.ServiceAccessControlDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.ServiceAccessControlOffset), acid.ServiceAccessControlSize);
npdm.KernelCapabilityDescriptor = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.KernelCapabilityOffset), acid.KernelCapabilitySize);
npdm.FsAccessControlDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.FsAccessControlOffset), acid.FsAccessControlSize);
npdm.ServiceAccessControlDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.ServiceAccessControlOffset), acid.ServiceAccessControlSize);
npdm.KernelCapabilityDescriptor = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AcidHeaderData, byte>(ref acid), acid.KernelCapabilityOffset), acid.KernelCapabilitySize);
npdm.FsAccessControlData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.FsAccessControlOffset), aci.FsAccessControlSize);
npdm.ServiceAccessControlData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.ServiceAccessControlOffset), aci.ServiceAccessControlSize);
npdm.KernelCapabilityData = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.KernelCapabilityOffset), aci.KernelCapabilitySize);
npdm.FsAccessControlData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.FsAccessControlOffset), aci.FsAccessControlSize);
npdm.ServiceAccessControlData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.ServiceAccessControlOffset), aci.ServiceAccessControlSize);
npdm.KernelCapabilityData = SpanHelpers.CreateReadOnlySpan(in Unsafe.Add(ref Unsafe.As<AciHeader, byte>(ref aci), aci.KernelCapabilityOffset), aci.KernelCapabilitySize);
return npdm;
}

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -53,12 +54,13 @@ public struct NsoHeader
public Array32<byte> RoHash;
public Array32<byte> DataHash;
[UnscopedRef]
public Span<SegmentHeader> Segments =>
SpanHelpers.CreateSpan(ref Unsafe.As<uint, SegmentHeader>(ref TextFileOffset), SegmentCount);
public Span<uint> CompressedSizes => SpanHelpers.CreateSpan(ref TextFileSize, SegmentCount);
[UnscopedRef] public Span<uint> CompressedSizes => SpanHelpers.CreateSpan(ref TextFileSize, SegmentCount);
public Span<Array32<byte>> SegmentHashes => SpanHelpers.CreateSpan(ref TextHash, SegmentCount);
[UnscopedRef] public Span<Array32<byte>> SegmentHashes => SpanHelpers.CreateSpan(ref TextHash, SegmentCount);
[Flags]
public enum Flag

View file

@ -1,5 +1,4 @@
using System;
using LibHac.Common;
using LibHac.Common.FixedArrays;
using LibHac.Ncm;
@ -9,9 +8,9 @@ namespace LibHac.Loader;
public ref struct Npdm
{
public ReadOnlyRef<Meta> Meta;
public ReadOnlyRef<AcidHeaderData> Acid;
public ReadOnlyRef<AciHeader> Aci;
public ref readonly Meta Meta;
public ref readonly AcidHeaderData Acid;
public ref readonly AciHeader Aci;
public ReadOnlySpan<byte> FsAccessControlDescriptor;
public ReadOnlySpan<byte> ServiceAccessControlDescriptor;

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -36,6 +37,7 @@ public struct ContentId : IEquatable<ContentId>, IComparable<ContentId>, ICompar
public void ToBytes(Span<byte> output) => Id.ToBytes(output);
[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -36,6 +37,7 @@ public struct PlaceHolderId : IEquatable<PlaceHolderId>, IComparable<PlaceHolder
public void ToBytes(Span<byte> output) => Id.ToBytes(output);
[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);

View file

@ -71,18 +71,18 @@ public struct ApplicationControlProperty
public AccessibleLaunchRequiredVersionValue AccessibleLaunchRequiredVersion;
public Array3000<byte> Reserved3448;
public readonly U8Span IsbnString => new U8Span(Isbn.ItemsRo);
public readonly U8Span DisplayVersionString => new U8Span(DisplayVersion.ItemsRo);
public readonly U8Span ApplicationErrorCodeCategoryString => new U8Span(ApplicationErrorCodeCategory.ItemsRo);
public readonly U8Span BcatPassphraseString => new U8Span(BcatPassphrase.ItemsRo);
[UnscopedRef] public readonly U8Span IsbnString => new U8Span(Isbn.ItemsRo);
[UnscopedRef] public readonly U8Span DisplayVersionString => new U8Span(DisplayVersion.ItemsRo);
[UnscopedRef] public readonly U8Span ApplicationErrorCodeCategoryString => new U8Span(ApplicationErrorCodeCategory.ItemsRo);
[UnscopedRef] public readonly U8Span BcatPassphraseString => new U8Span(BcatPassphrase.ItemsRo);
public struct ApplicationTitle
{
public Array512<byte> Name;
public Array256<byte> Publisher;
public readonly U8Span NameString => new U8Span(Name.ItemsRo);
public readonly U8Span PublisherString => new U8Span(Publisher.ItemsRo);
[UnscopedRef] public readonly U8Span NameString => new U8Span(Name.ItemsRo);
[UnscopedRef] public readonly U8Span PublisherString => new U8Span(Publisher.ItemsRo);
}
public struct ApplicationNeighborDetectionClientConfiguration

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;
@ -9,7 +10,7 @@ public struct AccessKey : IEquatable<AccessKey>
{
private readonly Key128 Key;
public ReadOnlySpan<byte> Value => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public ReadOnlySpan<byte> Value => SpanHelpers.AsByteSpan(ref this);
public AccessKey(ReadOnlySpan<byte> bytes)
{

View file

@ -1016,8 +1016,8 @@ public static class CharacterEncoding
return CharacterEncodingResult.Success;
}
public static CharacterEncodingResult PickOutCharacterFromUtf8String(Span<byte> destinationChar,
ref ReadOnlySpan<byte> source)
public static CharacterEncodingResult PickOutCharacterFromUtf8String(scoped Span<byte> destinationChar,
scoped ref ReadOnlySpan<byte> source)
{
Assert.SdkRequires(destinationChar.Length >= 4);
Assert.SdkRequires(source.Length >= 1);

View file

@ -1,6 +1,5 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using LibHac.Diag;
namespace LibHac.Util;
@ -14,20 +13,21 @@ public struct Optional<T>
public ref T Value
{
[UnscopedRef]
get
{
Assert.SdkRequires(_hasValue);
// It's beautiful, working around C# rules
return ref MemoryMarshal.GetReference(SpanHelpers.CreateSpan(ref _value, 1));
return ref _value;
}
}
public readonly ref readonly T ValueRo
{
[UnscopedRef]
get
{
Assert.SdkRequires(_hasValue);
return ref MemoryMarshal.GetReference(SpanHelpers.CreateReadOnlySpan(in _value, 1));
return ref _value;
}
}

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
@ -23,10 +23,9 @@
<ProjectReference Include="..\LibHac\LibHac.csproj" />
</ItemGroup>
<!-- Options for use with CoreRT -->
<ItemGroup Condition=" $(BuildType.StartsWith('native')) ">
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
</ItemGroup>
<PropertyGroup Condition=" $(BuildType.StartsWith('native')) ">
<PublishAot>true</PublishAot>
</PropertyGroup>
<PropertyGroup Condition=" $(BuildType.StartsWith('native')) and '$(BuildType)' != 'native-untrimmed' ">
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>