aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/qmake2cmake/qmake_parser.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/qmake2cmake/qmake_parser.py b/src/qmake2cmake/qmake_parser.py
index 5f4e938..e3e831f 100755
--- a/src/qmake2cmake/qmake_parser.py
+++ b/src/qmake2cmake/qmake_parser.py
@@ -419,11 +419,23 @@ class QmakeParser:
return result, contents
+parser_singleton = None
+
+
+# Return a single parser instance for every parsing operation, because
+# instantiating a parser is expensive.
+def get_qmake_parser(debug: bool = False) -> QmakeParser:
+ global parser_singleton
+ if not parser_singleton:
+ parser_singleton = QmakeParser(debug=debug)
+ return parser_singleton
+
+
def parseProFile(file: str, *, debug=False) -> Tuple[pp.ParseResults, str]:
- parser = QmakeParser(debug=debug)
+ parser = get_qmake_parser(debug=debug)
return parser.parseFile(file)
def parseProFileContents(contents: str, *, debug=False) -> Tuple[pp.ParseResults, str]:
- parser = QmakeParser(debug=debug)
+ parser = get_qmake_parser(debug=debug)
return parser.parseFileContents(contents)