Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slowdown after generating backslash escape sequences #91

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lmformatenforcer/jsonschemaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ def can_end(self) -> bool:
return all(parser.can_end() for parser in self.object_stack)

def shortcut_key(self) -> Optional[Hashable]:
if self.object_stack:
current_parser = self.object_stack[-1]
current_parsers = []
for parser in reversed(self.object_stack):
current_parsers.append(parser)
if not parser.can_end() or len(parser.get_allowed_characters()) > 0:
break

for current_parser in current_parsers:
if isinstance(current_parser, StringParsingState):
if not current_parser.allowed_strings and current_parser.seen_opening_quote and not current_parser.seen_closing_quote and not current_parser.regex_parser:
# Performance optimization: When we are parsing a string that is not from a list of allowed strings, most tokens
Expand Down
Loading