Skip to content

Minor performance improvements to the BaseUnits class (v5) #1452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions UnitsNet/BaseUnits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public BaseUnits(
Temperature = temperature;
Amount = amount;
LuminousIntensity = luminousIntensity;

IsFullyDefined = Length is not null &&
Mass is not null &&
Time is not null &&
Current is not null &&
Temperature is not null &&
Amount is not null &&
LuminousIntensity is not null;
}

/// <inheritdoc />
Expand All @@ -72,6 +64,9 @@ public bool Equals(BaseUnits? other)
if (other is null)
return false;

if (ReferenceEquals(this, other))
return true;

return Length == other.Length &&
Mass == other.Mass &&
Time == other.Time &&
Expand Down Expand Up @@ -108,7 +103,11 @@ public bool IsSubsetOf(BaseUnits other)
/// <inheritdoc />
public override int GetHashCode()
{
#if NET
return HashCode.Combine(Length, Mass, Time, Current, Temperature, Amount, LuminousIntensity);
#else
return new {Length, Mass, Time, Current, Temperature, Amount, LuminousIntensity}.GetHashCode();
#endif
}

/// <summary>
Expand Down Expand Up @@ -198,8 +197,19 @@ string GetDefaultAbbreviation<TUnitType>(TUnitType? unitOrNull) where TUnitType
public LuminousIntensityUnit? LuminousIntensity{ get; }

/// <summary>
/// Gets whether or not all of the base units are defined.
/// Gets a value indicating whether all base units are defined.
/// </summary>
public bool IsFullyDefined { get; }
/// <remarks>
/// This property returns <c>true</c> if all seven base units
/// (Length, Mass, Time, Current, Temperature, Amount, and LuminousIntensity)
/// are non-null; otherwise, it returns <c>false</c>.
/// </remarks>
public bool IsFullyDefined => Length is not null &&
Mass is not null &&
Time is not null &&
Current is not null &&
Temperature is not null &&
Amount is not null &&
LuminousIntensity is not null;
}
}
Loading