Convert `Bit` to a `readonly record struct`
This commit is contained in:
parent
f458acbbb4
commit
14032a5b1c
|
@ -3,15 +3,8 @@ using System.Diagnostics;
|
||||||
namespace BizHawk.Common
|
namespace BizHawk.Common
|
||||||
{
|
{
|
||||||
// I think this is a little faster with uint than with byte
|
// I think this is a little faster with uint than with byte
|
||||||
public readonly struct Bit
|
public readonly record struct Bit(uint _val)
|
||||||
{
|
{
|
||||||
private readonly uint _val;
|
|
||||||
|
|
||||||
public Bit(uint val)
|
|
||||||
{
|
|
||||||
_val = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator Bit(int rhs)
|
public static implicit operator Bit(int rhs)
|
||||||
{
|
{
|
||||||
Debug.Assert((rhs & ~1) is 0, "higher bits can't be used");
|
Debug.Assert((rhs & ~1) is 0, "higher bits can't be used");
|
||||||
|
@ -37,25 +30,5 @@ namespace BizHawk.Common
|
||||||
{
|
{
|
||||||
return _val.ToString();
|
return _val.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(Bit lhs, Bit rhs)
|
|
||||||
{
|
|
||||||
return lhs._val == rhs._val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator !=(Bit lhs, Bit rhs)
|
|
||||||
{
|
|
||||||
return lhs._val != rhs._val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return _val.GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
|
||||||
{
|
|
||||||
return obj is Bit b && this == b;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue