Skip to content

Commit 244da6a

Browse files
committed
move back to PyDict_SetItem
1 parent 4324ead commit 244da6a

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ where
225225
}
226226
major::MAP => {
227227
let len = types::Map::len(r)?.expect("contains length");
228-
let mut prev_key: Option<&[u8]> = None;
228+
let dict = PyDict::new(py);
229229

230-
let mut items: Vec<(Py<PyAny>, Py<PyAny>)> = Vec::with_capacity(len);
230+
let mut prev_key: Option<&[u8]> = None;
231231
for _ in 0..len {
232232
// DAG-CBOR keys are always strings. Python does the UTF-8 validation when creating
233233
// the string.
@@ -246,17 +246,9 @@ where
246246
prev_key = Some(key);
247247

248248
let value_py = decode_dag_cbor_to_pyobject(py, r, depth + 1)?;
249-
250-
items.push((key_py.unbind().into(), value_py));
251-
}
252-
253-
let seq = PyList::empty(py);
254-
for (key, value) in items {
255-
let pair = PyTuple::new(py, &[key, value])?;
256-
seq.append(pair)?;
249+
dict.set_item(key_py, value_py)?;
257250
}
258251

259-
let dict = PyDict::from_sequence(&seq)?;
260252
dict.into_pyobject(py)?.into()
261253
}
262254
major::TAG => {

0 commit comments

Comments
 (0)