summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/primitives/array.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-01-22 14:18:18 +0100
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-06-17 12:29:56 +0300
commitf3366a7e543f69844bd3658db65c28295912db79 (patch)
treec845b67716730a01ff7b7d3f3f7c30a50f679daa /mesonbuild/interpreter/primitives/array.py
parent992a93bcef47972c75464d1878c4c4b0469b1fbf (diff)
downloadmeson-f3366a7e543f69844bd3658db65c28295912db79.tar.gz
interpreter: make trivial_operators per-class
Do not call update() and Enum.__hash__ a gazillion times; trivial operators are the same for every instance of the class. Introduce the infrastructure to build the MRO-resolved operators (so the outcome same as if one called super().__init__) for each subclass of InterpreterObject. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/interpreter/primitives/array.py')
-rw-r--r--mesonbuild/interpreter/primitives/array.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/mesonbuild/interpreter/primitives/array.py b/mesonbuild/interpreter/primitives/array.py
index 6582d4b60..088f1758b 100644
--- a/mesonbuild/interpreter/primitives/array.py
+++ b/mesonbuild/interpreter/primitives/array.py
@@ -27,6 +27,14 @@ if T.TYPE_CHECKING:
from ...interpreterbase import TYPE_kwargs
class ArrayHolder(ObjectHolder[T.List[TYPE_var]], IterableObject):
+ # Operators that only require type checks
+ TRIVIAL_OPERATORS = {
+ MesonOperator.EQUALS: (list, lambda obj, x: obj.held_object == x),
+ MesonOperator.NOT_EQUALS: (list, lambda obj, x: obj.held_object != x),
+ MesonOperator.IN: (object, lambda obj, x: x in obj.held_object),
+ MesonOperator.NOT_IN: (object, lambda obj, x: x not in obj.held_object),
+ }
+
def __init__(self, obj: T.List[TYPE_var], interpreter: 'Interpreter') -> None:
super().__init__(obj, interpreter)
self.methods.update({
@@ -35,13 +43,6 @@ class ArrayHolder(ObjectHolder[T.List[TYPE_var]], IterableObject):
'get': self.get_method,
})
- self.trivial_operators.update({
- MesonOperator.EQUALS: (list, lambda obj, x: obj.held_object == x),
- MesonOperator.NOT_EQUALS: (list, lambda obj, x: obj.held_object != x),
- MesonOperator.IN: (object, lambda obj, x: x in obj.held_object),
- MesonOperator.NOT_IN: (object, lambda obj, x: x not in obj.held_object),
- })
-
# Use actual methods for functions that require additional checks
self.operators.update({
MesonOperator.PLUS: ArrayHolder.op_plus,