[Python-checkins] python/dist/src/Objects abstract.c,2.121,2.122
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Jan 4 06:00:10 EST 2004
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv5064/Objects
Modified Files:
abstract.c
Log Message:
Apply pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects.
Now, any object that reports its length can benefit from pre-sizing.
Index: abstract.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -d -r2.121 -r2.122
*** abstract.c 4 Jan 2004 06:08:16 -0000 2.121
--- abstract.c 4 Jan 2004 11:00:08 -0000 2.122
***************
*** 1449,1461 ****
/* Guess a result list size. */
! n = -1; /* unknown */
! if (PySequence_Check(v) &&
! v->ob_type->tp_as_sequence->sq_length) {
! n = PySequence_Size(v);
! if (n < 0)
! PyErr_Clear();
! }
! if (n < 0)
n = 8; /* arbitrary */
result = PyList_New(n);
if (result == NULL) {
--- 1449,1457 ----
/* Guess a result list size. */
! n = PyObject_Size(v);
! if (n < 0) {
! PyErr_Clear();
n = 8; /* arbitrary */
+ }
result = PyList_New(n);
if (result == NULL) {
More information about the Python-checkins
mailing list