Commits

birkenfeld  committed 926a895

Implement list multiplication.

  • Participants
  • Parent commits 7dae9f8

Comments (0)

Files changed (1)

File arana/list.c

 }
 
 static AR
+arana_list_mul(AR_SIG, AR self, AR args)
+{
+    AR other;
+    AR_PARSE(args, "I::mul", &other);
+    unsigned long times = AR_AS_LONG(other);
+    if (times < 0)
+        times = 0;
+    Ar_size_t size = AR_LIST_SIZE(self);
+    Ar_size_t totalsize = size * times;
+    ArList *result = (ArList *)AR_LIST2(totalsize);
+    AR *cur = result->items;
+    for (int i = 0; i < times; ++i) {
+        memcpy(cur, ((ArList *)self)->items, sizeof(AR)*size);
+        cur += size;
+    }
+    result->size = totalsize;
+    return (AR)result;
+}
+
+static AR
 arana_list_length(AR_SIG, AR self, AR args)
 {
     AR_ASSERT_EMPTY_ARGS(args, "length");
     AR_BIND_METHOD(type, ":getitem", arana_list_get);
     AR_BIND_METHOD(type, ":setitem", arana_list_set);
     AR_BIND_METHOD(type, ":concat", arana_list_concat);
+    AR_BIND_METHOD(type, ":mul", arana_list_mul);
     AR_BIND_METHOD(type, "length", arana_list_length);
     AR_BIND_METHOD(type, "append", arana_list_append);
     AR_BIND_METHOD(type, "delete", arana_list_delete);