Skip to content

Commit

Permalink
Performance improvement: if units are the same, no conversion is need…
Browse files Browse the repository at this point in the history
…ed to compare
  • Loading branch information
petermorlion committed May 11, 2016
1 parent 28de41f commit d2e2b10
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions RedStar.Amounts/Amount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ public Amount Power(int power)
/// </summary>
public static bool operator <(Amount left, Amount right)
{
if (left.Unit == right.Unit)
{
return (left != right) && (left._value < right._value);
}

var rightConverted = right.ConvertedTo(left._unit);
return (left != rightConverted) && (left._value < rightConverted._value);
}
Expand All @@ -389,6 +394,11 @@ public Amount Power(int power)
/// </summary>
public static bool operator <=(Amount left, Amount right)
{
if (left.Unit == right.Unit)
{
return (left == right) || (left._value < right._value);
}

var rightConverted = right.ConvertedTo(left._unit);
return (left == rightConverted) || (left._value < rightConverted._value);
}
Expand All @@ -398,6 +408,11 @@ public Amount Power(int power)
/// </summary>
public static bool operator >(Amount left, Amount right)
{
if (left.Unit == right.Unit)
{
return (left != right) && (left._value > right._value);
}

var rightConverted = right.ConvertedTo(left._unit);
return (left != rightConverted) && (left._value > rightConverted._value);
}
Expand All @@ -407,6 +422,11 @@ public Amount Power(int power)
/// </summary>
public static bool operator >=(Amount left, Amount right)
{
if (left.Unit == right.Unit)
{
return (left == right) || (left._value > right._value);
}

var rightConverted = right.ConvertedTo(left._unit);
return (left == rightConverted) || (left._value > rightConverted._value);
}
Expand Down

0 comments on commit d2e2b10

Please sign in to comment.