From b6c87797721fcdfd9b8ed87d993e16ca87138044 Mon Sep 17 00:00:00 2001
From: Massimiliano Culpo <massimiliano.culpo@gmail.com>
Date: Tue, 7 Jun 2022 17:51:16 +0200
Subject: Use __slots__ for fast attribute access during parsing

---
 lib/spack/spack/parse.py | 6 ++++++
 lib/spack/spack/spec.py  | 2 ++
 2 files changed, 8 insertions(+)

(limited to 'lib')

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.
 
-- 
cgit v1.2.3-70-g09d2