Skip to content

Commit

Permalink
Add changelog / some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Jan 10, 2022
1 parent 4bc06ff commit ac1d8d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -24,6 +24,8 @@
at least one pre-existing blank line (#2736)
- Verbose mode also now describes how a project root was discovered and which paths will
be formatted. (#2526)
- Speed-up the new backtracking parser about 4X in general (enabled when
`--target-version` is set to 3.10 and higher). (#2728)

### Packaging

Expand Down
13 changes: 5 additions & 8 deletions src/blib2to3/pgen2/parse.py
Expand Up @@ -73,7 +73,7 @@ def ilabels(self) -> Set[int]:

@contextmanager
def switch_to(self, ilabel: int) -> Iterator[None]:
with self.patch():
with self.backtrack():
self.parser.stack = self._points[ilabel]
try:
yield
Expand All @@ -83,12 +83,11 @@ def switch_to(self, ilabel: int) -> Iterator[None]:
self.parser.stack = self._start_point

@contextmanager
def patch(self) -> Iterator[None]:
def backtrack(self) -> Iterator[None]:
"""
Patch basic state operations (push/pop/shift) with node-level
immutable variants. These still will operate on the stack; but
they won't create any new nodes, or modify the contents of any
other existing nodes.
Use the node-level invariant ones for basic parsing operations (push/pop/shift).
These still will operate on the stack; but they won't create any new nodes, or
modify the contents of any other existing nodes.
This saves us a ton of time when we are backtracking, since we
want to restore to the initial state as quick as possible, which
Expand Down Expand Up @@ -349,8 +348,6 @@ def classify(self, type: int, value: Text, context: Context) -> List[int]:
raise ParseError("bad token", type, value, context)
return [ilabel]

STATE_OPERATIONS = ["shift", "push", "pop"]

def shift(self, type: int, value: Text, newstate: int, context: Context) -> None:
"""Shift a token. (Internal)"""
if self.is_backtracking:
Expand Down

0 comments on commit ac1d8d8

Please sign in to comment.