Skip to content

Commit 9ed5137

Browse files
committed
__slot__ optimisation
1 parent 3ed6f1e commit 9ed5137

File tree

4 files changed

+4
-17
lines changed

4 files changed

+4
-17
lines changed

benchmarks/fibonacci.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def mesure_io(nb):
4949
return statistics.median(l)
5050

5151

52-
print(io.marker)
5352
print(f"fibo({n}) : {mesure(t)}")
5453
print(f"fibo_io({n}) : {mesure_io(t)}")
5554
print(f"fibo({n}) : {mesure(t)}")

conda/raffiot/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "raffiot" %}
2-
{% set version = "0.0.6.2" %}
2+
{% set version = "0.0.6.3" %}
33

44
package:
55
name: "{{ name|lower }}"

src/raffiot/io.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class IO(Generic[R, E, A]):
3838
Have a look to the documentation and examples to learn how to use it.
3939
"""
4040

41+
__slots__ = "__tag", "__fields"
42+
4143
@final
4244
def __init__(self, __tag, __fields):
4345
self.__tag = __tag
@@ -49,8 +51,6 @@ def map(self, f: Callable[[A], A2]) -> IO[R, E, A2]:
4951
Transform the computed value with f if the computation is successful.
5052
Do nothing otherwise.
5153
"""
52-
if self.__tag in [9, 12]:
53-
return self
5454
return IO(1, (self, f))
5555

5656
@final
@@ -78,8 +78,6 @@ def ap(self: IO[R, E, Callable[[X], A]], arg: IO[R, E, X]) -> IO[R, E, A]:
7878
and arg computes a value `x: X`
7979
then self.ap(arg) computes `f(x): A`
8080
"""
81-
if self.__tag == 0 and arg.__tag == 0:
82-
return IO(5, lambda: self.__fields(arg.__fields))
8381
return IO(3, (self, arg))
8482

8583
@final
@@ -99,8 +97,6 @@ def contra_map_read(self, f: Callable[[R2], R]) -> IO[R2, E, A]:
9997
Transform the context with f.
10098
Note that f is not from R to R2 but from R2 to R!
10199
"""
102-
if self.__tag in [0, 5, 9, 12]:
103-
return self
104100
return IO(8, (f, self))
105101

106102
# Error API
@@ -112,8 +108,6 @@ def catch(self, handler: Callable[[E], IO[R, E, A]]) -> IO[R, E, A]:
112108
113109
On error, call the handler with the error.
114110
"""
115-
if self.__tag in [0, 5, 7, 12]:
116-
return self
117111
return IO(10, (self, handler))
118112

119113
@final
@@ -122,8 +116,6 @@ def map_error(self, f: Callable[[E], E2]) -> IO[R, E2, A]:
122116
Transform the stored error if the computation fails on an error.
123117
Do nothing otherwise.
124118
"""
125-
if self.__tag in [0, 5, 7, 12]:
126-
return self
127119
return IO(11, (self, f))
128120

129121
# Panic
@@ -135,8 +127,6 @@ def recover(self, handler: Callable[[Exception], IO[R, E, A]]) -> IO[R, E, A]:
135127
136128
On panic, call the handler with the exception.
137129
"""
138-
if self.__tag in [0, 7, 9]:
139-
return self
140130
return IO(13, (self, handler))
141131

142132
@final
@@ -145,8 +135,6 @@ def map_panic(self, f: Callable[[E], E2]) -> IO[R, E2, A]:
145135
Transform the exception stored if the computation fails on a panic.
146136
Do nothing otherwise.
147137
"""
148-
if self.__tag in [0, 7, 9]:
149-
return self
150138
return IO(14, (self, f))
151139

152140
@final

src/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
version = "0.0.6.2"
3+
version = "0.0.6.3"
44

55
with open("README.md", "r", encoding="utf-8") as fh:
66
long_description = fh.read()

0 commit comments

Comments
 (0)