-
-
Notifications
You must be signed in to change notification settings - Fork 298
Open
Description
A module of mine has tens of (nested) element definitions, all have .leave_whitespace() called; it takes several seconds to run. It took me quite some time to realize that pyparsing were making copies of nested elements, which is unnecessary for my use case:
Lines 3738 to 3749 in fad68f4
| def leave_whitespace(self, recursive: bool = True) -> ParserElement: | |
| """ | |
| Extends ``leave_whitespace`` defined in base class, and also invokes ``leave_whitespace`` on | |
| all contained expressions. | |
| """ | |
| super().leave_whitespace(recursive) | |
| if recursive: | |
| self.exprs = [e.copy() for e in self.exprs] | |
| for e in self.exprs: | |
| e.leave_whitespace(recursive) | |
| return self |
Lines 4524 to 4531 in fad68f4
| def leave_whitespace(self, recursive: bool = True) -> ParserElement: | |
| super().leave_whitespace(recursive) | |
| if recursive: | |
| if self.expr is not None: | |
| self.expr = self.expr.copy() | |
| self.expr.leave_whitespace(recursive) | |
| return self |
In the same spirit with recursive (#219), I think another parameter should also be introduced to configure the behavior.
Metadata
Metadata
Assignees
Labels
No labels