From 57378bfbaaf9821a886bb6adb73afcd3ac6c742b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 10 Aug 2019 20:02:45 +0200 Subject: [PATCH] Use slots for faster access --- lihzahrd/tiles/block.py | 2 ++ lihzahrd/tiles/frameimportantdata.py | 2 ++ lihzahrd/tiles/liquid.py | 2 ++ lihzahrd/tiles/tile.py | 1 + lihzahrd/tiles/wall.py | 2 ++ lihzahrd/tiles/wires.py | 4 +++- 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lihzahrd/tiles/block.py b/lihzahrd/tiles/block.py index a093235..038bbb6 100644 --- a/lihzahrd/tiles/block.py +++ b/lihzahrd/tiles/block.py @@ -4,6 +4,8 @@ from .frameimportantdata import FrameImportantData class Block: + __slots__ = "type", "frame", "paint", "is_active" + def __init__(self, type_: BlockType, frame: typing.Optional[FrameImportantData], diff --git a/lihzahrd/tiles/frameimportantdata.py b/lihzahrd/tiles/frameimportantdata.py index c9d63c5..cc37dc2 100644 --- a/lihzahrd/tiles/frameimportantdata.py +++ b/lihzahrd/tiles/frameimportantdata.py @@ -1,4 +1,6 @@ class FrameImportantData: + __slots__ = "frame_x", "frame_y" + def __init__(self, frame_x, frame_y): self.frame_x: int = frame_x self.frame_y: int = frame_y diff --git a/lihzahrd/tiles/liquid.py b/lihzahrd/tiles/liquid.py index 9ff9e9c..1d3178b 100644 --- a/lihzahrd/tiles/liquid.py +++ b/lihzahrd/tiles/liquid.py @@ -2,6 +2,8 @@ from .liquidtype import LiquidType class Liquid: + __slots__ = "type", "volume" + def __init__(self, type_: LiquidType, volume: int): self.type: LiquidType = type_ self.volume: int = volume diff --git a/lihzahrd/tiles/tile.py b/lihzahrd/tiles/tile.py index 7eb43d5..59a080c 100644 --- a/lihzahrd/tiles/tile.py +++ b/lihzahrd/tiles/tile.py @@ -5,6 +5,7 @@ from .liquid import Liquid class Tile: + __slots__ = "block", "wall", "liquid" def __init__(self, block: typing.Optional[Block], wall: typing.Optional[Wall], liquid: typing.Optional[Liquid]): self.block: typing.Optional[Block] = block diff --git a/lihzahrd/tiles/wall.py b/lihzahrd/tiles/wall.py index 19d0e55..28a0039 100644 --- a/lihzahrd/tiles/wall.py +++ b/lihzahrd/tiles/wall.py @@ -3,6 +3,8 @@ from .walltype import WallType class Wall: + __slots__ = "type", "paint" + def __init__(self, type_: WallType, paint: typing.Optional[int]): self.type: WallType = type_ self.paint: typing.Optional[int] = paint diff --git a/lihzahrd/tiles/wires.py b/lihzahrd/tiles/wires.py index 7586c5c..1e194f8 100644 --- a/lihzahrd/tiles/wires.py +++ b/lihzahrd/tiles/wires.py @@ -1,4 +1,6 @@ class Wires: + __slots__ = "red", "green", "blue", "yellow", "actuator" + def __init__(self, red: bool = False, green: bool = False, @@ -12,4 +14,4 @@ class Wires: self.actuator: bool = actuator def __repr__(self): - return f"Wires(red={self.red}, green={self.green}, blue={self.blue}, yellow={self.yellow}, actuator={self.actuator})" \ No newline at end of file + return f"Wires(red={self.red}, green={self.green}, blue={self.blue}, yellow={self.yellow}, actuator={self.actuator})"