1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Performance improvement using in-operator for hash lookups

Just a small cleanup for the existing occurrences.

Using the in-operator for hash lookups is faster than using .has_key()
http://stackoverflow.com/questions/1323410/has-key-or-in
This commit is contained in:
Dag Wieers 2016-11-17 15:53:43 +01:00 committed by Matt Clay
parent 85f6c26dff
commit c843eeabc2
2 changed files with 3 additions and 3 deletions

View file

@ -163,7 +163,7 @@ class Rhn(RegistrationBase):
def get_option_default(self, key, default=''): def get_option_default(self, key, default=''):
# ignore pep8 W601 errors for this line # ignore pep8 W601 errors for this line
# setting this to use 'in' does not work in the rhn library # setting this to use 'in' does not work in the rhn library
if self.has_key(key): if key in self:
return self[key] return self[key]
else: else:
return default return default

View file

@ -1715,7 +1715,7 @@ class DarwinUser(User):
self.chown_homedir(int(self.uid), int(self.group), self.home) self.chown_homedir(int(self.uid), int(self.group), self.home)
for field in self.fields: for field in self.fields:
if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]: if field[0] in self.__dict__ and self.__dict__[field[0]]:
cmd = self._get_dscl() cmd = self._get_dscl()
cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]] cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
@ -1752,7 +1752,7 @@ class DarwinUser(User):
self._make_group_numerical() self._make_group_numerical()
for field in self.fields: for field in self.fields:
if self.__dict__.has_key(field[0]) and self.__dict__[field[0]]: if field[0] in self.__dict__ and self.__dict__[field[0]]:
current = self._get_user_property(field[1]) current = self._get_user_property(field[1])
if current is None or current != self.__dict__[field[0]]: if current is None or current != self.__dict__[field[0]]:
cmd = self._get_dscl() cmd = self._get_dscl()