Skip to content

Commit 4f57bf8

Browse files
committed
Use static *_Type objects
1 parent 21808b8 commit 4f57bf8

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/typeref.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::ffi::c_void;
66
use core::ffi::CStr;
77
#[cfg(feature = "yyjson")]
88
use core::mem::MaybeUninit;
9-
use core::ptr::{null, null_mut, NonNull};
9+
use core::ptr::{null_mut, NonNull};
1010
use once_cell::race::{OnceBool, OnceBox};
1111

1212
#[cfg(feature = "yyjson")]
@@ -144,37 +144,33 @@ fn _init_typerefs_impl() -> bool {
144144
crate::serialize::writer::set_str_formatter_fn();
145145
crate::str::set_str_create_fn();
146146

147-
FRAGMENT_TYPE = orjson_fragmenttype_new();
148-
PyDateTime_IMPORT();
149147
NONE = Py_None();
150148
TRUE = Py_True();
151149
FALSE = Py_False();
152150
EMPTY_UNICODE = PyUnicode_New(0, 255);
153-
STR_TYPE = (*EMPTY_UNICODE).ob_type;
154-
BYTES_TYPE = (*PyBytes_FromStringAndSize(null(), 0)).ob_type;
155151

156-
{
157-
let bytearray = PyByteArray_FromStringAndSize(null(), 0);
158-
BYTEARRAY_TYPE = (*bytearray).ob_type;
152+
STR_TYPE = &raw mut PyUnicode_Type;
153+
BYTES_TYPE = &raw mut PyBytes_Type;
154+
DICT_TYPE = &raw mut PyDict_Type;
155+
LIST_TYPE = &raw mut PyList_Type;
156+
TUPLE_TYPE = &raw mut PyTuple_Type;
157+
NONE_TYPE = (*NONE).ob_type;
158+
BOOL_TYPE = &raw mut PyBool_Type;
159+
INT_TYPE = &raw mut PyLong_Type;
160+
FLOAT_TYPE = &raw mut PyFloat_Type;
161+
BYTEARRAY_TYPE = &raw mut PyByteArray_Type;
162+
MEMORYVIEW_TYPE = &raw mut PyMemoryView_Type;
159163

160-
let memoryview = PyMemoryView_FromObject(bytearray);
161-
MEMORYVIEW_TYPE = (*memoryview).ob_type;
162-
Py_DECREF(memoryview);
163-
Py_DECREF(bytearray);
164-
}
164+
PyDateTime_IMPORT();
165165

166-
DICT_TYPE = (*PyDict_New()).ob_type;
167-
LIST_TYPE = (*PyList_New(0)).ob_type;
168-
TUPLE_TYPE = (*PyTuple_New(0)).ob_type;
169-
NONE_TYPE = (*NONE).ob_type;
170-
BOOL_TYPE = (*TRUE).ob_type;
171-
INT_TYPE = (*PyLong_FromLongLong(0)).ob_type;
172-
FLOAT_TYPE = (*PyFloat_FromDouble(0.0)).ob_type;
173166
DATETIME_TYPE = look_up_datetime_type();
174167
DATE_TYPE = look_up_date_type();
175168
TIME_TYPE = look_up_time_type();
176169
UUID_TYPE = look_up_uuid_type();
177170
ENUM_TYPE = look_up_enum_type();
171+
172+
FRAGMENT_TYPE = orjson_fragmenttype_new();
173+
178174
FIELD_TYPE = look_up_field_type();
179175
ZONEINFO_TYPE = look_up_zoneinfo_type();
180176

0 commit comments

Comments
 (0)