Skip to content

Commit 63076a5

Browse files
committed
__slots__ optimization
1 parent 7bd1e82 commit 63076a5

13 files changed

Lines changed: 35 additions & 3 deletions

File tree

flatdata-generator/flatdata/generator/templates/py/python.jinja2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import flatdata.lib as flatdata
1010
{{ struct.doc|to_python_doc}}
1111
class {{ tree.namespace_path(struct, "_") }}_{{ struct.name }}(flatdata.structure.Structure):
1212
"""{{ struct.doc|safe_py_string_line }}"""
13+
__slots__ = ()
1314
_SCHEMA = """{{ tree.schema(struct) }}"""
1415
_NAME = "{{ tree.namespace_path(struct, "_") }}_{{ struct.name }}"
1516
_SIZE_IN_BITS = {{ struct.size_in_bits }}

flatdata-generator/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "flatdata-generator"
7-
version = "0.4.10"
7+
version = "0.4.11"
88
description = "Generate source code for C++, Rust, Go or Python from a Flatdata schema file"
99
readme = "README.md"
1010
authors = [

flatdata-generator/tests/generators/py_expectations/archives/multivector.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class n_S(flatdata.structure.Structure):
22
""""""
3+
__slots__ = ()
34
_SCHEMA = """namespace n {
45
struct S
56
{
@@ -20,6 +21,7 @@ class n_S(flatdata.structure.Structure):
2021

2122
class n_T(flatdata.structure.Structure):
2223
""""""
24+
__slots__ = ()
2325
_SCHEMA = """namespace n {
2426
struct T
2527
{
@@ -40,6 +42,7 @@ class n_T(flatdata.structure.Structure):
4042
# Builtin type to for MultiVector index
4143
class n__builtin_multivector_IndexType8(flatdata.structure.Structure):
4244
"""/** Builtin type to for MultiVector index */"""
45+
__slots__ = ()
4346
_SCHEMA = """"""
4447
_NAME = "n__builtin_multivector_IndexType8"
4548
_SIZE_IN_BITS = 8
@@ -53,6 +56,7 @@ class n__builtin_multivector_IndexType8(flatdata.structure.Structure):
5356
# Builtin type to for MultiVector index
5457
class n__builtin_multivector_IndexType16(flatdata.structure.Structure):
5558
"""/** Builtin type to for MultiVector index */"""
59+
__slots__ = ()
5660
_SCHEMA = """"""
5761
_NAME = "n__builtin_multivector_IndexType16"
5862
_SIZE_IN_BITS = 16
@@ -66,6 +70,7 @@ class n__builtin_multivector_IndexType16(flatdata.structure.Structure):
6670
# Builtin type to for MultiVector index
6771
class n__builtin_multivector_IndexType64(flatdata.structure.Structure):
6872
"""/** Builtin type to for MultiVector index */"""
73+
__slots__ = ()
6974
_SCHEMA = """"""
7075
_NAME = "n__builtin_multivector_IndexType64"
7176
_SIZE_IN_BITS = 64

flatdata-generator/tests/generators/py_expectations/archives/namespaces.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class n_S(flatdata.structure.Structure):
22
""""""
3+
__slots__ = ()
34
_SCHEMA = """namespace n {
45
struct S
56
{
@@ -92,6 +93,7 @@ def __init__(self, resource_storage):
9293

9394
class m_S(flatdata.structure.Structure):
9495
""""""
96+
__slots__ = ()
9597
_SCHEMA = """namespace m {
9698
struct S
9799
{
@@ -184,6 +186,7 @@ def __init__(self, resource_storage):
184186
# Builtin type to for MultiVector index
185187
class a__builtin_multivector_IndexType32(flatdata.structure.Structure):
186188
"""/** Builtin type to for MultiVector index */"""
189+
__slots__ = ()
187190
_SCHEMA = """"""
188191
_NAME = "a__builtin_multivector_IndexType32"
189192
_SIZE_IN_BITS = 32

flatdata-generator/tests/generators/py_expectations/archives/ranges.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class n_S(flatdata.structure.Structure):
22
""""""
3+
__slots__ = ()
34
_SCHEMA = """namespace n {
45
struct S
56
{

flatdata-generator/tests/generators/py_expectations/archives/struct.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class n_S(flatdata.structure.Structure):
22
""""""
3+
__slots__ = ()
34
_SCHEMA = """namespace n {
45
struct S
56
{

flatdata-generator/tests/generators/py_expectations/archives/vector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class n_S(flatdata.structure.Structure):
22
""""""
3+
__slots__ = ()
34
_SCHEMA = """namespace n {
45
struct S
56
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This is a comment about Foo
22
class n_Foo(flatdata.structure.Structure):
33
"""// This is a comment about Foo"""
4+
__slots__ = ()
45
_SCHEMA = """namespace n {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# This is a comment about Foo
22
class n_Foo(flatdata.structure.Structure):
3-
"""// This is a comment about Foo"""
3+
"""// This is a comment about Foo"""
4+
__slots__ = ()

flatdata-generator/tests/generators/py_expectations/structs/integers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class n_U8(flatdata.structure.Structure):
1414
""""""
15+
__slots__ = ()
1516
_SCHEMA = """namespace n {
1617
struct U8
1718
{
@@ -32,6 +33,7 @@ class n_U8(flatdata.structure.Structure):
3233

3334
class n_I8(flatdata.structure.Structure):
3435
""""""
36+
__slots__ = ()
3537
_SCHEMA = """namespace n {
3638
struct I8
3739
{
@@ -52,6 +54,7 @@ class n_I8(flatdata.structure.Structure):
5254

5355
class n_U16(flatdata.structure.Structure):
5456
""""""
57+
__slots__ = ()
5558
_SCHEMA = """namespace n {
5659
struct U16
5760
{
@@ -72,6 +75,7 @@ class n_U16(flatdata.structure.Structure):
7275

7376
class n_I16(flatdata.structure.Structure):
7477
""""""
78+
__slots__ = ()
7579
_SCHEMA = """namespace n {
7680
struct I16
7781
{
@@ -92,6 +96,7 @@ class n_I16(flatdata.structure.Structure):
9296

9397
class n_U32(flatdata.structure.Structure):
9498
""""""
99+
__slots__ = ()
95100
_SCHEMA = """namespace n {
96101
struct U32
97102
{
@@ -112,6 +117,7 @@ class n_U32(flatdata.structure.Structure):
112117

113118
class n_I32(flatdata.structure.Structure):
114119
""""""
120+
__slots__ = ()
115121
_SCHEMA = """namespace n {
116122
struct I32
117123
{
@@ -132,6 +138,7 @@ class n_I32(flatdata.structure.Structure):
132138

133139
class n_U64(flatdata.structure.Structure):
134140
""""""
141+
__slots__ = ()
135142
_SCHEMA = """namespace n {
136143
struct U64
137144
{
@@ -152,6 +159,7 @@ class n_U64(flatdata.structure.Structure):
152159

153160
class n_I64(flatdata.structure.Structure):
154161
""""""
162+
__slots__ = ()
155163
_SCHEMA = """namespace n {
156164
struct I64
157165
{

0 commit comments

Comments
 (0)