From c8a700834c8906d55b4458b38e9e7eb1227fd47f Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Thu, 17 Nov 2016 16:02:09 +0100 Subject: [PATCH] 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 --- lib/ansible/modules/extras/system/crypttab.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/system/crypttab.py b/lib/ansible/modules/extras/system/crypttab.py index d004f8fa4f6..b8834a23c8a 100644 --- a/lib/ansible/modules/extras/system/crypttab.py +++ b/lib/ansible/modules/extras/system/crypttab.py @@ -312,7 +312,7 @@ class Options(dict): def add(self, opts_string): changed = False for k, v in Options(opts_string).items(): - if self.has_key(k): + if k in self: if self[k] != v: changed = True else: @@ -323,7 +323,7 @@ class Options(dict): def remove(self, opts_string): changed = False for k in Options(opts_string): - if self.has_key(k): + if k in self: del self[k] changed = True return changed, 'removed options' @@ -341,7 +341,7 @@ class Options(dict): return iter(self.itemlist) def __setitem__(self, key, value): - if not self.has_key(key): + if key not in self: self.itemlist.append(key) super(Options, self).__setitem__(key, value)