This commit is contained in:
Eugene Sadovoi 2019-05-21 10:29:46 -04:00
Родитель 65f9bc12d8
Коммит 3db3623c8e
1 изменённых файлов: 20 добавлений и 12 удалений

Просмотреть файл

@ -8,7 +8,7 @@ namespace Unity.Storage
#region Fields
public readonly int HashCode;
private readonly int _type;
public readonly Type Type;
private readonly int _name;
#endregion
@ -18,30 +18,30 @@ namespace Unity.Storage
public HashKey(int _ = 0)
{
_type = 0;
_name = 0;
HashCode = 0;
Type = typeof(NoType);
}
public HashKey(Type type)
{
_type = type?.GetHashCode() ?? 0;
_name = -1;
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
HashCode = NamedType.GetHashCode(type?.GetHashCode() ?? 0, _name) & UnityContainer.HashMask;
Type = type;
}
public HashKey(string? name)
{
_type = name?.Length ?? 0;
_name = name?.GetHashCode() ?? 0;
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
HashCode = NamedType.GetHashCode(typeof(NoType), name) & UnityContainer.HashMask;
Type = typeof(NoType);
}
public HashKey(Type type, string? name)
{
_type = type?.GetHashCode() ?? 0;
_name = name?.GetHashCode() ?? 0;
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
HashCode = NamedType.GetHashCode(type, name) & UnityContainer.HashMask;
Type = type;
}
#endregion
@ -63,7 +63,7 @@ namespace Unity.Storage
public bool Equals(HashKey other)
{
return other.HashCode == HashCode &&
other._type == _type &&
other.Type == Type &&
other._name == _name;
}
@ -71,7 +71,7 @@ namespace Unity.Storage
{
return obj is HashKey other &&
other.HashCode == HashCode &&
other._type == _type &&
other.Type == Type &&
other._name == _name;
}
@ -80,16 +80,24 @@ namespace Unity.Storage
public static bool operator ==(HashKey x, HashKey y)
{
return x.HashCode == y.HashCode &&
x._type == y._type &&
x.Type == y.Type &&
x._name == y._name;
}
public static bool operator !=(HashKey x, HashKey y)
{
return x.HashCode != y.HashCode ||
x._type != y._type ||
x.Type != y.Type ||
x._name != y._name;
}
#endregion
#region NoType
private class NoType { }
#endregion
}
}