chore: Use var everywhere (#2294)
This commit is contained in:
parent
0b34cc4417
commit
ebaf104935
267 changed files with 873 additions and 873 deletions
|
|
@ -94,7 +94,7 @@ public static class AdhocPersistence
|
|||
|
||||
byte* ptr = null;
|
||||
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
|
||||
UnmanagedDataReader dataReader = new UnmanagedDataReader(ptr, accessor.Length);
|
||||
var dataReader = new UnmanagedDataReader(ptr, accessor.Length);
|
||||
deserializer(dataReader);
|
||||
|
||||
error = dataReader.Position != fileLength
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
*/
|
||||
private unsafe Dictionary<ulong, ConstructorInfo> ReadTypes(string savePath)
|
||||
{
|
||||
string typesPath = Path.Combine(savePath, Name, $"{Name}.tdb");
|
||||
var typesPath = Path.Combine(savePath, Name, $"{Name}.tdb");
|
||||
if (!File.Exists(typesPath))
|
||||
{
|
||||
return [];
|
||||
|
|
@ -209,7 +209,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
|
||||
public virtual void DeserializeIndexes(string savePath, Dictionary<ulong, string> typesDb)
|
||||
{
|
||||
string indexPath = Path.Combine(savePath, Name, $"{Name}.idx");
|
||||
var indexPath = Path.Combine(savePath, Name, $"{Name}.idx");
|
||||
|
||||
_entities ??= [];
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
ctors[hash] = ctor = GetConstructorFor(typeName, AssemblyHandler.FindTypeByHash(hash), ctorArguments);
|
||||
}
|
||||
|
||||
Serial serial = (Serial)dataReader.ReadUInt();
|
||||
var serial = (Serial)dataReader.ReadUInt();
|
||||
var created = version == 0 ? now : new DateTime(dataReader.ReadLong(), DateTimeKind.Utc);
|
||||
if (version is > 0 and < 3)
|
||||
{
|
||||
|
|
@ -330,7 +330,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
|
||||
public override void Deserialize(string savePath, Dictionary<ulong, string> typesDb)
|
||||
{
|
||||
string dataPath = Path.Combine(savePath, Name, $"{Name}.bin");
|
||||
var dataPath = Path.Combine(savePath, Name, $"{Name}.bin");
|
||||
var fi = new FileInfo(dataPath);
|
||||
|
||||
if (!fi.Exists)
|
||||
|
|
@ -354,7 +354,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
|
||||
byte* ptr = null;
|
||||
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
|
||||
UnmanagedDataReader dataReader = new UnmanagedDataReader(ptr, accessor.Length, typesDb);
|
||||
var dataReader = new UnmanagedDataReader(ptr, accessor.Length, typesDb);
|
||||
|
||||
Deserialize(dataReader);
|
||||
|
||||
|
|
@ -362,7 +362,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
|
||||
foreach (var entry in _entities[index])
|
||||
{
|
||||
T t = entry.Entity;
|
||||
var t = entry.Entity;
|
||||
|
||||
if (entry.Length == 0)
|
||||
{
|
||||
|
|
@ -527,7 +527,7 @@ public class GenericEntityPersistence<T> : GenericPersistence, IGenericEntityPer
|
|||
case WorldState.PendingSave:
|
||||
case WorldState.Running:
|
||||
{
|
||||
ref var entityEntry = ref CollectionsMarshal.GetValueRefOrAddDefault(EntitiesBySerial, entity.Serial, out bool exists);
|
||||
ref var entityEntry = ref CollectionsMarshal.GetValueRefOrAddDefault(EntitiesBySerial, entity.Serial, out var exists);
|
||||
if (exists)
|
||||
{
|
||||
if (entityEntry == entity)
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public interface IGenericReader
|
|||
}
|
||||
IPAddress ReadIPAddress()
|
||||
{
|
||||
byte length = ReadByte();
|
||||
var length = ReadByte();
|
||||
// Either 2 ushorts, or 8 ushorts
|
||||
Span<byte> integer = stackalloc byte[length];
|
||||
Read(integer);
|
||||
|
|
@ -120,8 +120,8 @@ public interface IGenericReader
|
|||
|
||||
public BitArray ReadBitArray()
|
||||
{
|
||||
int bitLength = ReadEncodedInt();
|
||||
int byteLength = (bitLength + 7) / 8;
|
||||
var bitLength = ReadEncodedInt();
|
||||
var byteLength = (bitLength + 7) / 8;
|
||||
|
||||
var buffer = ArrayPool<byte>.Shared.Rent(byteLength);
|
||||
try
|
||||
|
|
|
|||
|
|
@ -163,8 +163,8 @@ public interface IGenericWriter
|
|||
|
||||
public void Write(BitArray bitArray)
|
||||
{
|
||||
int bitLength = bitArray.Length;
|
||||
int byteLength = (bitLength + 7) / 8;
|
||||
var bitLength = bitArray.Length;
|
||||
var byteLength = (bitLength + 7) / 8;
|
||||
|
||||
WriteEncodedInt(bitLength);
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public abstract class Persistence
|
|||
{
|
||||
var db = new Dictionary<ulong, string>();
|
||||
|
||||
string typesPath = Path.Combine(path, "SerializedTypes.db");
|
||||
var typesPath = Path.Combine(path, "SerializedTypes.db");
|
||||
if (!File.Exists(typesPath))
|
||||
{
|
||||
return db;
|
||||
|
|
@ -96,7 +96,7 @@ public abstract class Persistence
|
|||
|
||||
public static void WriteSerializedTypesSnapshot(string path, HashSet<Type> types)
|
||||
{
|
||||
string typesPath = Path.Combine(path, "SerializedTypes.db");
|
||||
var typesPath = Path.Combine(path, "SerializedTypes.db");
|
||||
using var fs = new FileStream(typesPath, FileMode.Create);
|
||||
using var writer = new MemoryMapFileWriter(fs, 1024 * 1024 * 4);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public static class SerializationExtensions
|
|||
|
||||
public static T ReadEntity<T>(this IGenericReader reader) where T : class, ISerializable
|
||||
{
|
||||
Serial serial = reader.ReadSerial();
|
||||
var serial = reader.ReadSerial();
|
||||
var typeT = typeof(T);
|
||||
|
||||
T entity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue