Skip to content

Commit

Permalink
Avoid list creation at every simple call
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Jun 30, 2022
1 parent 3519412 commit 9da1b18
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sqlfluff/core/parser/parsers.py
Expand Up @@ -101,6 +101,8 @@ def __init__(
**segment_kwargs,
):
self.template = template.upper()
# Create list version upfront to avoid recreating it multiple times.
self._simple = [self.template]
super().__init__(
raw_class=raw_class,
name=name,
Expand All @@ -115,7 +117,7 @@ def simple(self, parse_context: "ParseContext") -> Optional[List[str]]:
Because string matchers are not case sensitive we can
just return the template here.
"""
return [self.template]
return self._simple

def _is_first_match(self, segment: BaseSegment):
"""Does the segment provided match according to the current rules."""
Expand All @@ -139,6 +141,8 @@ def __init__(
**segment_kwargs,
):
self.templates = {template.upper() for template in templates}
# Create list version upfront to avoid recreating it multiple times.
self._simple = list(self.templates)
super().__init__(
raw_class=raw_class,
name=name,
Expand All @@ -153,7 +157,7 @@ def simple(self, parse_context: "ParseContext") -> Optional[List[str]]:
Because string matchers are not case sensitive we can
just return the templates here.
"""
return list(self.templates)
return self._simple

def _is_first_match(self, segment: BaseSegment):
"""Does the segment provided match according to the current rules."""
Expand Down

0 comments on commit 9da1b18

Please sign in to comment.