From 79d1862510331701308618001d8989e3b42f32af Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 11 Apr 2015 01:07:18 +0200 Subject: [PATCH] models: Compare stream of items for models __eq__ Creating dictionaries for this is was just wasteful. --- mopidy/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mopidy/models.py b/mopidy/models.py index 477b87a7..230c86cc 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals import copy import inspect +import itertools import json import weakref @@ -225,7 +226,8 @@ class ImmutableObject(object): def __eq__(self, other): if not isinstance(other, self.__class__): return False - return dict(self._items()) == dict(other._items()) + return all(a == b for a, b in itertools.izip_longest( + self._items(), other._items(), fillvalue=object())) def __ne__(self, other): return not self.__eq__(other)