@@ -1878,19 +1878,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
1878
1878
goto invalid ;
1879
1879
}
1880
1880
1881
- if (options -> is_raw_bson ) {
1882
- value = PyObject_CallFunction (
1883
- options -> document_class , "y#O" ,
1884
- buffer + * position , (Py_ssize_t )size , options -> options_obj );
1885
- if (!value ) {
1886
- goto invalid ;
1887
- }
1888
- * position += size ;
1889
- break ;
1890
- }
1891
-
1892
- value = elements_to_dict (self , buffer + * position + 4 ,
1893
- size - 5 , options );
1881
+ value = elements_to_dict (self , buffer + * position ,
1882
+ size , options );
1894
1883
if (!value ) {
1895
1884
goto invalid ;
1896
1885
}
@@ -2456,8 +2445,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
2456
2445
if (buffer [* position + scope_size - 1 ]) {
2457
2446
goto invalid ;
2458
2447
}
2459
- scope = elements_to_dict (self , buffer + * position + 4 ,
2460
- scope_size - 5 , options );
2448
+ scope = elements_to_dict (self , buffer + * position ,
2449
+ scope_size , options );
2461
2450
if (!scope ) {
2462
2451
Py_DECREF (code );
2463
2452
goto invalid ;
@@ -2809,9 +2798,14 @@ static PyObject* elements_to_dict(PyObject* self, const char* string,
2809
2798
unsigned max ,
2810
2799
const codec_options_t * options ) {
2811
2800
PyObject * result ;
2801
+ if (options -> is_raw_bson ) {
2802
+ return PyObject_CallFunction (
2803
+ options -> document_class , "y#O" ,
2804
+ string , max , options -> options_obj );
2805
+ }
2812
2806
if (Py_EnterRecursiveCall (" while decoding a BSON document" ))
2813
2807
return NULL ;
2814
- result = _elements_to_dict (self , string , max , options );
2808
+ result = _elements_to_dict (self , string + 4 , max - 5 , options );
2815
2809
Py_LeaveRecursiveCall ();
2816
2810
return result ;
2817
2811
}
@@ -2902,15 +2896,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
2902
2896
goto done ;
2903
2897
}
2904
2898
2905
- /* No need to decode fields if using RawBSONDocument */
2906
- if (options .is_raw_bson ) {
2907
- result = PyObject_CallFunction (
2908
- options .document_class , "y#O" , string , (Py_ssize_t )size ,
2909
- options_obj );
2910
- }
2911
- else {
2912
- result = elements_to_dict (self , string + 4 , (unsigned )size - 5 , & options );
2913
- }
2899
+ result = elements_to_dict (self , string , (unsigned )size , & options );
2914
2900
done :
2915
2901
PyBuffer_Release (& view );
2916
2902
destroy_codec_options (& options );
@@ -2988,14 +2974,7 @@ static PyObject* _cbson_decode_all(PyObject* self, PyObject* args) {
2988
2974
goto fail ;
2989
2975
}
2990
2976
2991
- /* No need to decode fields if using RawBSONDocument. */
2992
- if (options .is_raw_bson ) {
2993
- dict = PyObject_CallFunction (
2994
- options .document_class , "y#O" , string , (Py_ssize_t )size ,
2995
- options_obj );
2996
- } else {
2997
- dict = elements_to_dict (self , string + 4 , (unsigned )size - 5 , & options );
2998
- }
2977
+ dict = elements_to_dict (self , string , (unsigned )size , & options );
2999
2978
if (!dict ) {
3000
2979
Py_DECREF (result );
3001
2980
goto fail ;
0 commit comments