From 8314da76e8004b912aae6dad29bf3d77cbad6911 Mon Sep 17 00:00:00 2001 From: Noam Bernstein Date: Tue, 20 Feb 2024 13:08:56 -0500 Subject: [PATCH] Faster reading of actual configs for a ConfigSet that has _file_loc set, as e.g. created by ConfigSet.groups() iterator --- wfl/configset.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wfl/configset.py b/wfl/configset.py index cbf9e9f9..25436c33 100644 --- a/wfl/configset.py +++ b/wfl/configset.py @@ -143,6 +143,18 @@ def __iter__(self): if self.items is None: return + # special handling for ConfigSet generated by groups() iterator, which + # sets self._cur_at, self._file_loc, and self._open_reader + if self._file_loc is not None and len(self._file_loc) > 0 and self._cur_at[0] is not None: + assert self._open_reader is not None + while self._cur_at[0].info["_ConfigSet_loc"].startswith(self._file_loc): + yield self._cur_at[0] + try: + self._cur_at[0] = next(self._open_reader) + except StopIteration: + break + return + if isinstance(self.items, Path): # yield Atoms from one file ## print("DEBUG __iter__ one file", self.items)