Index: Modules/arraymodule.c =================================================================== --- Modules/arraymodule.c (revision 61850) +++ Modules/arraymodule.c (working copy) @@ -668,22 +668,33 @@ array_repeat(arrayobject *a, Py_ssize_t n) { Py_ssize_t i; + Py_ssize_t j; Py_ssize_t size; arrayobject *np; - char *p; - Py_ssize_t nbytes; + Py_ssize_t oldbytes, newbytes; if (n < 0) n = 0; size = Py_SIZE(a) * n; np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); if (np == NULL) return NULL; - p = np->ob_item; - nbytes = Py_SIZE(a) * a->ob_descr->itemsize; - for (i = 0; i < n; i++) { - memcpy(p, a->ob_item, nbytes); - p += nbytes; + oldbytes = Py_SIZE(a) * a->ob_descr->itemsize; + newbytes = oldbytes * n; + if (oldbytes == 1 && n > 0) { + memset(np->ob_item, a->ob_item[0], newbytes); + return (PyObject *) np; } + i = 0; + if (i < newbytes) { + Py_MEMCPY(np->ob_item, a->ob_item, oldbytes); + i = oldbytes; + } + while (i < newbytes) { + j = (i <= newbytes-i) ? i : newbytes-i; + Py_MEMCPY(np->ob_item+i, np->ob_item, j); + i += j; + } + return (PyObject *) np; } Index: Lib/test/test_array.py =================================================================== --- Lib/test/test_array.py (revision 61850) +++ Lib/test/test_array.py (working copy) @@ -308,6 +308,12 @@ array.array(self.typecode) ) + a = 5 * array.array(self.typecode, self.example[:1]) + self.assertEqual( + a, + array.array(self.typecode, [a[0]] * 5) + ) + self.assertRaises(TypeError, a.__mul__, "bad") def test_imul(self):