@@ -97,23 +97,16 @@ STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) {
9797 (void )n_args ;
9898 mp_obj_btree_t * self = MP_OBJ_TO_PTR (args [0 ]);
9999 DBT key , val ;
100- // Different ports may have different type sizes
101- mp_uint_t v ;
102- key .data = (void * )mp_obj_str_get_data (args [1 ], & v );
103- key .size = v ;
104- val .data = (void * )mp_obj_str_get_data (args [2 ], & v );
105- val .size = v ;
100+ key .data = (void * )mp_obj_str_get_data (args [1 ], & key .size );
101+ val .data = (void * )mp_obj_str_get_data (args [2 ], & val .size );
106102 return MP_OBJ_NEW_SMALL_INT (__bt_put (self -> db , & key , & val , 0 ));
107103}
108104STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (btree_put_obj , 3 , 4 , btree_put );
109105
110106STATIC mp_obj_t btree_get (size_t n_args , const mp_obj_t * args ) {
111107 mp_obj_btree_t * self = MP_OBJ_TO_PTR (args [0 ]);
112108 DBT key , val ;
113- // Different ports may have different type sizes
114- mp_uint_t v ;
115- key .data = (void * )mp_obj_str_get_data (args [1 ], & v );
116- key .size = v ;
109+ key .data = (void * )mp_obj_str_get_data (args [1 ], & key .size );
117110 int res = __bt_get (self -> db , & key , & val , 0 );
118111 if (res == RET_SPECIAL ) {
119112 if (n_args > 2 ) {
@@ -132,10 +125,7 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) {
132125 int flags = MP_OBJ_SMALL_INT_VALUE (args [1 ]);
133126 DBT key , val ;
134127 if (n_args > 2 ) {
135- // Different ports may have different type sizes
136- mp_uint_t v ;
137- key .data = (void * )mp_obj_str_get_data (args [2 ], & v );
138- key .size = v ;
128+ key .data = (void * )mp_obj_str_get_data (args [2 ], & key .size );
139129 }
140130
141131 int res = __bt_seq (self -> db , & key , & val , flags );
@@ -206,14 +196,11 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
206196 mp_obj_btree_t * self = MP_OBJ_TO_PTR (self_in );
207197 DBT key , val ;
208198 int res ;
209- // Different ports may have different type sizes
210- mp_uint_t v ;
211199 bool desc = self -> flags & FLAG_DESC ;
212200 if (self -> start_key != MP_OBJ_NULL ) {
213201 int flags = R_FIRST ;
214202 if (self -> start_key != mp_const_none ) {
215- key .data = (void * )mp_obj_str_get_data (self -> start_key , & v );
216- key .size = v ;
203+ key .data = (void * )mp_obj_str_get_data (self -> start_key , & key .size );
217204 flags = R_CURSOR ;
218205 } else if (desc ) {
219206 flags = R_LAST ;
@@ -231,8 +218,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
231218
232219 if (self -> end_key != mp_const_none ) {
233220 DBT end_key ;
234- end_key .data = (void * )mp_obj_str_get_data (self -> end_key , & v );
235- end_key .size = v ;
221+ end_key .data = (void * )mp_obj_str_get_data (self -> end_key , & end_key .size );
236222 BTREE * t = self -> db -> internal ;
237223 int cmp = t -> bt_cmp (& key , & end_key );
238224 if (desc ) {
@@ -264,13 +250,10 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
264250
265251STATIC mp_obj_t btree_subscr (mp_obj_t self_in , mp_obj_t index , mp_obj_t value ) {
266252 mp_obj_btree_t * self = MP_OBJ_TO_PTR (self_in );
267- // Different ports may have different type sizes
268- mp_uint_t v ;
269253 if (value == MP_OBJ_NULL ) {
270254 // delete
271255 DBT key ;
272- key .data = (void * )mp_obj_str_get_data (index , & v );
273- key .size = v ;
256+ key .data = (void * )mp_obj_str_get_data (index , & key .size );
274257 int res = __bt_delete (self -> db , & key , 0 );
275258 if (res == RET_SPECIAL ) {
276259 nlr_raise (mp_obj_new_exception (& mp_type_KeyError ));
@@ -280,8 +263,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
280263 } else if (value == MP_OBJ_SENTINEL ) {
281264 // load
282265 DBT key , val ;
283- key .data = (void * )mp_obj_str_get_data (index , & v );
284- key .size = v ;
266+ key .data = (void * )mp_obj_str_get_data (index , & key .size );
285267 int res = __bt_get (self -> db , & key , & val , 0 );
286268 if (res == RET_SPECIAL ) {
287269 nlr_raise (mp_obj_new_exception (& mp_type_KeyError ));
@@ -291,10 +273,8 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
291273 } else {
292274 // store
293275 DBT key , val ;
294- key .data = (void * )mp_obj_str_get_data (index , & v );
295- key .size = v ;
296- val .data = (void * )mp_obj_str_get_data (value , & v );
297- val .size = v ;
276+ key .data = (void * )mp_obj_str_get_data (index , & key .size );
277+ val .data = (void * )mp_obj_str_get_data (value , & val .size );
298278 int res = __bt_put (self -> db , & key , & val , 0 );
299279 CHECK_ERROR (res );
300280 return mp_const_none ;
@@ -305,10 +285,8 @@ STATIC mp_obj_t btree_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
305285 mp_obj_btree_t * self = MP_OBJ_TO_PTR (lhs_in );
306286 switch (op ) {
307287 case MP_BINARY_OP_IN : {
308- mp_uint_t v ;
309288 DBT key , val ;
310- key .data = (void * )mp_obj_str_get_data (rhs_in , & v );
311- key .size = v ;
289+ key .data = (void * )mp_obj_str_get_data (rhs_in , & key .size );
312290 int res = __bt_get (self -> db , & key , & val , 0 );
313291 CHECK_ERROR (res );
314292 return mp_obj_new_bool (res != RET_SPECIAL );
0 commit comments