Use ref readonly instead of in for SharedRef parameters

This commit is contained in:
Alex Barney 2024-05-04 22:43:40 -07:00
parent dd2b9fe2ca
commit e19ea92b90
8 changed files with 35 additions and 28 deletions

View file

@ -62,9 +62,9 @@ public class DefaultFsServerObjects
};
}
public static Result InitializeNcaReader(ref SharedRef<NcaReader> outReader, in SharedRef<IStorage> baseStorage,
in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector,
ContentAttributes contentAttributes)
public static Result InitializeNcaReader(ref SharedRef<NcaReader> outReader,
ref readonly SharedRef<IStorage> baseStorage, in NcaCompressionConfiguration compressionConfig,
IHash256GeneratorFactorySelector hashGeneratorFactorySelector, ContentAttributes contentAttributes)
{
throw new NotImplementedException();
}

View file

@ -10,7 +10,7 @@ namespace LibHac.FsSrv.FsCreator;
public interface ISaveDataFileSystemCreator : IDisposable
{
Result CreateRaw(ref SharedRef<IFile> outFile, in SharedRef<IFileSystem> fileSystem, ulong saveDataId, OpenMode openMode);
Result CreateRaw(ref SharedRef<IFile> outFile, ref readonly SharedRef<IFileSystem> fileSystem, ulong saveDataId, OpenMode openMode);
Result Create(ref SharedRef<ISaveDataFileSystem> outFileSystem, ref SharedRef<IFileSystem> baseFileSystem,
SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac,
@ -18,16 +18,18 @@ public interface ISaveDataFileSystemCreator : IDisposable
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible);
Result CreateExtraDataAccessor(ref SharedRef<ISaveDataExtraDataAccessor> outExtraDataAccessor,
in SharedRef<IStorage> baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, bool isReconstructible);
ref readonly SharedRef<IStorage> baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData,
bool isReconstructible);
Result CreateInternalStorage(ref SharedRef<IFileSystem> outFileSystem, in SharedRef<IFileSystem> baseFileSystem,
SaveDataSpaceId spaceId, ulong saveDataId, bool isDeviceUniqueMac, bool useUniqueKey1,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible);
Result CreateInternalStorage(ref SharedRef<IFileSystem> outFileSystem,
ref readonly SharedRef<IFileSystem> baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId,
bool isDeviceUniqueMac, bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter,
bool isReconstructible);
Result RecoverMasterHeader(in SharedRef<IFileSystem> baseFileSystem, ulong saveDataId, IBufferManager bufferManager,
bool isDeviceUniqueMac, bool isReconstructible);
Result RecoverMasterHeader(ref readonly SharedRef<IFileSystem> baseFileSystem, ulong saveDataId,
IBufferManager bufferManager, bool isDeviceUniqueMac, bool isReconstructible);
Result UpdateMac(in SharedRef<IFileSystem> baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac,
Result UpdateMac(ref readonly SharedRef<IFileSystem> baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac,
bool isReconstructible);
Result Format(in ValueSubStorage saveImageStorage, long blockSize, int countExpandMax, uint blockCount,
@ -47,7 +49,7 @@ public interface ISaveDataFileSystemCreator : IDisposable
void SetMacGenerationSeed(ReadOnlySpan<byte> seed);
Result IsProvisionallyCommittedSaveData(out bool outIsProvisionallyCommitted,
in SharedRef<IFileSystem> baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac,
ref readonly SharedRef<IFileSystem> baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible);
IMacGenerator GetMacGenerator(bool isDeviceUniqueMac, bool isTemporaryTransferSave);

View file

@ -281,7 +281,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
seed.CopyTo(_macGenerationSeed.Value);
}
public Result CreateRaw(ref SharedRef<IFile> outFile, in SharedRef<IFileSystem> fileSystem, ulong saveDataId, OpenMode openMode)
public Result CreateRaw(ref SharedRef<IFile> outFile, ref readonly SharedRef<IFileSystem> fileSystem,
ulong saveDataId, OpenMode openMode)
{
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
@ -419,7 +420,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
}
public Result CreateExtraDataAccessor(ref SharedRef<ISaveDataExtraDataAccessor> outExtraDataAccessor,
in SharedRef<IStorage> baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, bool isReconstructible)
ref readonly SharedRef<IStorage> baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData,
bool isReconstructible)
{
using var saveDataFs = new SharedRef<ISaveDataFileSystem>();
@ -455,8 +457,9 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
}
public Result CreateInternalStorage(ref SharedRef<IFileSystem> outFileSystem,
in SharedRef<IFileSystem> baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool isDeviceUniqueMac,
bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible)
ref readonly SharedRef<IFileSystem> baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId,
bool isDeviceUniqueMac, bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter,
bool isReconstructible)
{
Result res;
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
@ -510,7 +513,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
return Result.Success;
}
public Result RecoverMasterHeader(in SharedRef<IFileSystem> baseFileSystem, ulong saveDataId,
public Result RecoverMasterHeader(ref readonly SharedRef<IFileSystem> baseFileSystem, ulong saveDataId,
IBufferManager bufferManager, bool isDeviceUniqueMac, bool isReconstructible)
{
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
@ -554,8 +557,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
return Result.Success;
}
public Result UpdateMac(in SharedRef<IFileSystem> baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac,
bool isReconstructible)
public Result UpdateMac(ref readonly SharedRef<IFileSystem> baseFileSystem, ulong saveDataId,
bool isDeviceUniqueMac, bool isReconstructible)
{
Unsafe.SkipInit(out Array18<byte> saveImageNameBuffer);
@ -599,7 +602,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
}
public Result IsProvisionallyCommittedSaveData(out bool outIsProvisionallyCommitted,
in SharedRef<IFileSystem> baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac,
ref readonly SharedRef<IFileSystem> baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible)
{
UnsafeHelpers.SkipParamInit(out outIsProvisionallyCommitted);

View file

@ -38,8 +38,9 @@ public class SaveDataMover : ISaveDataMover
private State _state;
private SdkMutex _mutex;
public SaveDataMover(in SharedRef<ISaveDataTransferCoreInterface> transferInterface, SaveDataSpaceId sourceSpaceId,
SaveDataSpaceId destinationSpaceId, NativeHandle transferMemoryHandle, ulong transferMemorySize)
public SaveDataMover(ref readonly SharedRef<ISaveDataTransferCoreInterface> transferInterface,
SaveDataSpaceId sourceSpaceId, SaveDataSpaceId destinationSpaceId, NativeHandle transferMemoryHandle,
ulong transferMemorySize)
{
throw new NotImplementedException();
}

View file

@ -150,7 +150,7 @@ file static class Anonymous
return Result.Success;
static Result ReadData(in UniqueRef<IFile> file, ref CodeVerificationData outData)
static Result ReadData(ref readonly UniqueRef<IFile> file, ref CodeVerificationData outData)
{
Result res = file.Get.GetSize(out long verificationDataSize);
if (res.IsFailure()) return res.Miss();

View file

@ -551,7 +551,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable
using (var extraDataAccessor = new SharedRef<ISaveDataExtraDataAccessor>())
{
res = _config.SaveFsCreator.CreateExtraDataAccessor(ref extraDataAccessor.Ref, in saveDataStorage,
IsDeviceUniqueMac(spaceId), isIntegritySaveData: true, SaveDataProperties.IsReconstructible(type, spaceId));
IsDeviceUniqueMac(spaceId), isIntegritySaveData: true,
isReconstructible: SaveDataProperties.IsReconstructible(type, spaceId));
if (res.IsFailure()) return res.Miss();
res = extraDataAccessor.Get.ReadExtraData(out SaveDataExtraData extraData);

View file

@ -87,7 +87,7 @@ file class SharedNcaBodyStorage : IStorage
private SharedRef<IStorage> _storage;
private SharedRef<NcaReader> _ncaReader;
public SharedNcaBodyStorage(in SharedRef<IStorage> baseStorage, in SharedRef<NcaReader> ncaReader)
public SharedNcaBodyStorage(ref readonly SharedRef<IStorage> baseStorage, ref readonly SharedRef<NcaReader> ncaReader)
{
_storage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_ncaReader = SharedRef<NcaReader>.CreateCopy(in ncaReader);

View file

@ -8,9 +8,9 @@ using LibHac.Spl;
namespace LibHac.FsSystem;
public delegate Result NcaReaderInitializer(ref SharedRef<NcaReader> outReader, in SharedRef<IStorage> baseStorage,
in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector,
ContentAttributes contentAttributes);
public delegate Result NcaReaderInitializer(ref SharedRef<NcaReader> outReader,
ref readonly SharedRef<IStorage> baseStorage, in NcaCompressionConfiguration compressionConfig,
IHash256GeneratorFactorySelector hashGeneratorFactorySelector, ContentAttributes contentAttributes);
/// <summary>
/// Handles reading information from an NCA's header.