Skip to content

Commit

Permalink
Add cache to _get_root_units
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Nov 4, 2023
1 parent 5fad10b commit 829ddd7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ def get_root_units(

return f, self.Unit(units)

@methodcache
def _get_root_units(
self, input_units: UnitsContainer, check_nonmult: bool = True
) -> tuple[Scalar, UnitsContainer]:
Expand All @@ -824,12 +825,6 @@ def _get_root_units(
if not input_units:
return 1, self.UnitsContainer()

cache = self._cache.root_units
try:
return cache[input_units]
except KeyError:
pass

accumulators: dict[Optional[str], int] = defaultdict(int)
accumulators[None] = 1
self._get_root_units_recurse(input_units, 1, accumulators)
Expand All @@ -844,7 +839,6 @@ def _get_root_units(
if any(not self._units[unit].converter.is_multiplicative for unit in units):
factor = None

cache[input_units] = factor, units
return factor, units

def get_base_units(
Expand Down

0 comments on commit 829ddd7

Please sign in to comment.