diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 63add04481..9e2d18c785 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -768,10 +768,18 @@ def coord_dims(self, coord): The :class:`iris.coords.Coord` instance to look for. """ - target_defn = coord._as_defn() - - ### Search by coord definition first + # Search for existing coordinate (object) on the cube, faster lookup + # than equality - makes no functional difference. + matches = [(dim,) for coord_, dim in self._dim_coords_and_dims if + coord_ is coord] + if not matches: + matches = [dims for coord_, dims in self._aux_coords_and_dims if + coord_ is coord] + if matches: + return matches[0] + ## Search by coord definition (slow) + target_defn = coord._as_defn() # Search dim coords first matches = [(dim,) for coord_, dim in self._dim_coords_and_dims if coord_._as_defn() == target_defn]