Skip to content

Commit 1273e9e

Browse files
committed
Improve performances of _Fields.__contains__
The default implementation relies on __iter__, which is much slower and memory consuming than the new implementation which verifies directly whether a given field exists.
1 parent af062bd commit 1273e9e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

stagpy/_step.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ def __iter__(self):
232232
return (fld for fld in chain(self._vars, self._extra)
233233
if fld in self)
234234

235+
def __contains__(self, item):
236+
try:
237+
return self[item] is not None
238+
except error.StagpyError:
239+
return False
240+
235241
def __len__(self):
236242
return len(iter(self))
237243

0 commit comments

Comments
 (0)