summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-01-11 22:16:24 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-01-11 22:16:24 (GMT)
commit830c85d0bacc2366af8b75becca021e00e976298 (patch)
tree63f2112cfea98ae26524f175061dca91cbd67c06 /Modules/arraymodule.c
parentd501dde89d1ced7c5a96c727511b94d1b8d3a45c (diff)
downloadcpython-830c85d0bacc2366af8b75becca021e00e976298.zip
cpython-830c85d0bacc2366af8b75becca021e00e976298.tar.gz
cpython-830c85d0bacc2366af8b75becca021e00e976298.tar.bz2
Merged revisions 87942 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r87942 | alexander.belopolsky | 2011-01-11 16:44:00 -0500 (Tue, 11 Jan 2011) | 3 lines Issue #5109: array.array constructor will now use fast code when initial data is provided in an array object with correct type. ........
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 1602e48..ba07e02 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1925,7 +1925,10 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!(initial == NULL || PyList_Check(initial)
|| PyString_Check(initial) || PyTuple_Check(initial)
- || (c == 'u' && PyUnicode_Check(initial)))) {
+ || PyTuple_Check(initial)
+ || ((c=='u') && PyUnicode_Check(initial))
+ || (array_Check(initial)
+ && c == ((arrayobject*)initial)->ob_descr->typecode))) {
it = PyObject_GetIter(initial);
if (it == NULL)
return NULL;
@@ -1941,17 +1944,20 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *a;
Py_ssize_t len;
- if (initial == NULL || !(PyList_Check(initial)
- || PyTuple_Check(initial)))
+ if (initial == NULL)
len = 0;
+ else if (PyList_Check(initial))
+ len = PyList_GET_SIZE(initial);
+ else if (PyTuple_Check(initial) || array_Check(initial))
+ len = Py_SIZE(initial);
else
- len = PySequence_Size(initial);
+ len = 0;
a = newarrayobject(type, len, descr);
if (a == NULL)
return NULL;
- if (len > 0) {
+ if (len > 0 && !array_Check(initial)) {
Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *v =
@@ -2001,6 +2007,11 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
#endif
}
+ else if (initial != NULL && array_Check(initial)) {
+ arrayobject *self = (arrayobject *)a;
+ arrayobject *other = (arrayobject *)initial;
+ memcpy(self->ob_item, other->ob_item, len * other->ob_descr->itemsize);
+ }
if (it != NULL) {
if (array_iter_extend((arrayobject *)a, it) == -1) {
Py_DECREF(it);