File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,19 +14,24 @@ pub fn serialize(
1414 ptr : * mut pyo3:: ffi:: PyObject ,
1515 default : Option < NonNull < pyo3:: ffi:: PyObject > > ,
1616) -> PyResult < PyObject > {
17- let buf: Vec < u8 > = serde_json:: to_vec ( & SerializePyObject {
18- ptr : ptr,
19- default : default,
20- recursion : 0 ,
21- } )
17+ let mut buf: Vec < u8 > = Vec :: with_capacity ( 1008 ) ;
18+ {
19+ serde_json:: to_writer (
20+ & mut buf,
21+ & SerializePyObject {
22+ ptr : ptr,
23+ default : default,
24+ recursion : 0 ,
25+ } ,
26+ )
27+ }
2228 . map_err ( |error| JSONEncodeError :: py_err ( error. to_string ( ) ) ) ?;
23- let slice = buf. as_slice ( ) ;
2429 Ok ( unsafe {
2530 PyObject :: from_owned_ptr (
2631 py,
2732 pyo3:: ffi:: PyBytes_FromStringAndSize (
28- slice . as_ptr ( ) as * const c_char ,
29- slice . len ( ) as pyo3:: ffi:: Py_ssize_t ,
33+ buf . as_ptr ( ) as * const c_char ,
34+ buf . len ( ) as pyo3:: ffi:: Py_ssize_t ,
3035 ) ,
3136 )
3237 } )
You can’t perform that action at this time.
0 commit comments