diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2022-06-07 17:51:16 +0200 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2022-08-02 10:52:52 -0700 |
commit | b6c87797721fcdfd9b8ed87d993e16ca87138044 (patch) | |
tree | 516f0480bdfc175e9efb6c7ffb139be9c2c1b1fd /lib | |
parent | 57e6452831ff8bc0088b55069642c8204b0b76fb (diff) | |
download | spack-b6c87797721fcdfd9b8ed87d993e16ca87138044.tar.gz spack-b6c87797721fcdfd9b8ed87d993e16ca87138044.tar.bz2 spack-b6c87797721fcdfd9b8ed87d993e16ca87138044.tar.xz spack-b6c87797721fcdfd9b8ed87d993e16ca87138044.zip |
Use __slots__ for fast attribute access during parsing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/parse.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/spack/spack/parse.py b/lib/spack/spack/parse.py index 941cb5a93e..91cebe9063 100644 --- a/lib/spack/spack/parse.py +++ b/lib/spack/spack/parse.py @@ -17,6 +17,8 @@ import spack.util.path as sp class Token(object): """Represents tokens; generated from input by lexer and fed to parse().""" + __slots__ = 'type', 'value', 'start', 'end' + def __init__(self, type, value="", start=0, end=0): self.type = type self.value = value @@ -39,6 +41,8 @@ class Token(object): class Lexer(object): """Base class for Lexers that keep track of line numbers.""" + __slots__ = 'scanner0', 'scanner1', 'mode', 'mode_switches_01', 'mode_switches_10' + def __init__(self, lexicon0, mode_switches_01=[], lexicon1=[], mode_switches_10=[]): self.scanner0 = re.Scanner(lexicon0) self.mode_switches_01 = mode_switches_01 @@ -89,6 +93,8 @@ class Lexer(object): class Parser(object): """Base class for simple recursive descent parsers.""" + __slots__ = 'tokens', 'token', 'next', 'lexer', 'text' + def __init__(self, lexer): self.tokens = iter([]) # iterators over tokens, handled in order. self.token = Token(None) # last accepted token diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index d1ee8a4325..a325670289 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -4983,6 +4983,8 @@ _lexer = SpecLexer() class SpecParser(spack.parse.Parser): """Parses specs.""" + __slots__ = 'previous', '_initial' + def __init__(self, initial_spec=None): """Construct a new SpecParser. |