summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-12-06 00:56:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-12-06 00:56:53 (GMT)
commit4e2f714031654eb4174393454c008961b636f539 (patch)
treee415e4318c986483c73d9e5e01b9434a7be9ce83 /Python
parent923ad7a9488c9b514c8e27315179ada1d142f3e5 (diff)
downloadcpython-4e2f714031654eb4174393454c008961b636f539.zip
cpython-4e2f714031654eb4174393454c008961b636f539.tar.gz
cpython-4e2f714031654eb4174393454c008961b636f539.tar.bz2
Fix Issue 1045.
Factor-out common calling code by simplifying the length_hint API. Speed-up the function by caching the PyObject_String for the attribute lookup.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 1667d37..e1242fd 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -236,15 +236,7 @@ builtin_filter(PyObject *self, PyObject *args)
goto Fail_arg;
/* Guess a result list size. */
- len = _PyObject_LengthHint(seq);
- if (len < 0) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
- !PyErr_ExceptionMatches(PyExc_AttributeError)) {
- goto Fail_it;
- }
- PyErr_Clear();
- len = 8; /* arbitrary */
- }
+ len = _PyObject_LengthHint(seq, 8);
/* Get a result list. */
if (PyList_Check(seq) && seq->ob_refcnt == 1) {
@@ -905,15 +897,7 @@ builtin_map(PyObject *self, PyObject *args)
}
/* Update len. */
- curlen = _PyObject_LengthHint(curseq);
- if (curlen < 0) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
- !PyErr_ExceptionMatches(PyExc_AttributeError)) {
- goto Fail_2;
- }
- PyErr_Clear();
- curlen = 8; /* arbitrary */
- }
+ curlen = _PyObject_LengthHint(curseq, 8);
if (curlen > len)
len = curlen;
}
@@ -2243,13 +2227,8 @@ builtin_zip(PyObject *self, PyObject *args)
len = -1; /* unknown */
for (i = 0; i < itemsize; ++i) {
PyObject *item = PyTuple_GET_ITEM(args, i);
- Py_ssize_t thislen = _PyObject_LengthHint(item);
+ Py_ssize_t thislen = _PyObject_LengthHint(item, -1);
if (thislen < 0) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
- !PyErr_ExceptionMatches(PyExc_AttributeError)) {
- return NULL;
- }
- PyErr_Clear();
len = -1;
break;
}