From 314cb32c6828e72ce62b5a62fd91322de84c305d Mon Sep 17 00:00:00 2001 From: Carwyn Pelley Date: Fri, 28 Jun 2013 16:26:37 +0100 Subject: [PATCH] MAINT: coord_dims speedup This commit offers to speedup the comparison of supplied coordinate with that on the cube by way of checking if its the same object, then comparing by way of metadata if object not found. This in particular was targetting CubeList merging. --- lib/iris/cube.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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]