Skip to content

Commit

Permalink
Optimize the happy path of some unit computations with identical units.
Browse files Browse the repository at this point in the history
  • Loading branch information
maffoo committed Feb 17, 2017
1 parent 61fa17d commit cac38e7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions labrad/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def _convert_units(self, other):
(float, complex, array), and unit is their common unit.
"""
if isinstance(other, WithUnit):
if other.unit is self.unit:
return self._value, other._value, self.unit
if self.isCompatible(other):
if self.unit.conversionFactorTo(other.unit) > 1:
unit = other.unit
Expand Down Expand Up @@ -415,6 +417,8 @@ def _base_value(self):

def __getitem__(self, unit):
"""Return value of physical quantity expressed in new units."""
if unit is self.unit:
return self._value
if unit == self.unit:
return self._value
factor, offset = self.unit.conversionTupleTo(unit)
Expand Down

0 comments on commit cac38e7

Please sign in to comment.