From 28ab82aab013978b7ed91bda816de3d41385f260 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Mon, 6 Dec 2021 00:03:48 +0300 Subject: [PATCH] perf: drop the initial stack copy (#2670) Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com> --- CHANGES.md | 2 ++ src/blib2to3/pgen2/parse.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 097725e..434f809 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,8 @@ - Fix styling of starred expressions inside `match` subject (#2667) - Fix parser error location on invalid syntax in a `match` statement (#2649) - Fix Python 3.10 support on platforms without ProcessPoolExecutor (#2631) +- Improve parsing performance on code that uses `match` under `--target-version py310` + up to ~50% (#2670) ### Packaging diff --git a/src/blib2to3/pgen2/parse.py b/src/blib2to3/pgen2/parse.py index 792e8e6..e5dad3a 100644 --- a/src/blib2to3/pgen2/parse.py +++ b/src/blib2to3/pgen2/parse.py @@ -53,7 +53,7 @@ class Recorder: self.context = context # not really matter self._dead_ilabels: Set[int] = set() - self._start_point = copy.deepcopy(self.parser.stack) + self._start_point = self.parser.stack self._points = {ilabel: copy.deepcopy(self._start_point) for ilabel in ilabels} @property -- 2.39.2