In pure Python, _dict_to_bson simply returns the RawBSONDocument.raw attribute:
def _dict_to_bson(doc, check_keys, opts, top_level=True): """Encode a document to BSON.""" if _raw_document_class(doc): return doc.raw ...
In the C version _cbson_dict_to_bson, we copy the raw attribute to an intermediate buffer and then encode that buffer to a bytes instance. Let's just return the raw attribute the same way the python code does instead.
- is related to
-
PYTHON-1403 BSON.encode and BSON.decode perform an extra copy by design
- Closed