@@ -241,6 +241,39 @@ STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
241
241
STATIC mp_obj_t array_binary_op (mp_binary_op_t op , mp_obj_t lhs_in , mp_obj_t rhs_in ) {
242
242
mp_obj_array_t * lhs = MP_OBJ_TO_PTR (lhs_in );
243
243
switch (op ) {
244
+ case MP_BINARY_OP_MULTIPLY :
245
+ case MP_BINARY_OP_INPLACE_MULTIPLY : {
246
+ if (!MP_OBJ_IS_INT (rhs_in )) {
247
+ return MP_OBJ_NULL ; // op not supported
248
+ }
249
+ mp_uint_t repeat = mp_obj_get_int (rhs_in );
250
+ bool inplace = (op == MP_BINARY_OP_INPLACE_MULTIPLY );
251
+ mp_buffer_info_t lhs_bufinfo ;
252
+ array_get_buffer (lhs_in , & lhs_bufinfo , MP_BUFFER_READ );
253
+ mp_obj_array_t * res ;
254
+ byte * ptr ;
255
+ size_t orig_lhs_bufinfo_len = lhs_bufinfo .len ;
256
+ if (inplace ) {
257
+ res = lhs ;
258
+ size_t item_sz = mp_binary_get_size ('@' , lhs -> typecode , NULL );
259
+ lhs -> items = m_renew (byte , lhs -> items , (lhs -> len + lhs -> free ) * item_sz , lhs -> len * repeat * item_sz );
260
+ lhs -> len = lhs -> len * repeat ;
261
+ lhs -> free = 0 ;
262
+ if (!repeat )
263
+ return MP_OBJ_FROM_PTR (res );
264
+ repeat -- ;
265
+ ptr = (byte * )res -> items + orig_lhs_bufinfo_len ;
266
+ } else {
267
+ res = array_new (lhs_bufinfo .typecode , lhs -> len * repeat );
268
+ ptr = (byte * )res -> items ;
269
+ }
270
+ if (orig_lhs_bufinfo_len ) {
271
+ for (;repeat -- ; ptr += orig_lhs_bufinfo_len ) {
272
+ memcpy (ptr , lhs_bufinfo .buf , orig_lhs_bufinfo_len );
273
+ }
274
+ }
275
+ return MP_OBJ_FROM_PTR (res );
276
+ }
244
277
case MP_BINARY_OP_ADD : {
245
278
// allow to add anything that has the buffer protocol (extension to CPython)
246
279
mp_buffer_info_t lhs_bufinfo ;
0 commit comments