summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-02-25 20:39:11 (GMT)
committerThomas Wouters <thomas@python.org>2007-02-25 20:39:11 (GMT)
commit27d517b21b67b54637acd19785f7adfc38fbd8c2 (patch)
treef1d104da21500db8a9426bc39a6bc42488121099 /Objects
parent9a7e77401b5c8d084dfa286fc15b5db03155533d (diff)
downloadcpython-27d517b21b67b54637acd19785f7adfc38fbd8c2.zip
cpython-27d517b21b67b54637acd19785f7adfc38fbd8c2.tar.gz
cpython-27d517b21b67b54637acd19785f7adfc38fbd8c2.tar.bz2
Merged revisions 53875-53911 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c2
-rw-r--r--Objects/exceptions.c3
-rw-r--r--Objects/intobject.c3
-rw-r--r--Objects/listobject.c2
-rw-r--r--Objects/longobject.c3
-rw-r--r--Objects/stringobject.c17
-rw-r--r--Objects/tupleobject.c2
-rw-r--r--Objects/typeobject.c20
-rw-r--r--Objects/unicodeobject.c3
9 files changed, 42 insertions, 13 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index ffa7a86..36a18e4 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2027,7 +2027,7 @@ PyTypeObject PyDict_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_BASETYPE | Py_TPFLAGS_DICT_SUBCLASS, /* tp_flags */
dictionary_doc, /* tp_doc */
dict_traverse, /* tp_traverse */
dict_tp_clear, /* tp_clear */
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 9e298f0..402bcec 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -300,7 +300,8 @@ static PyTypeObject _PyExc_BaseException = {
PyObject_GenericGetAttr, /*tp_getattro*/
PyObject_GenericSetAttr, /*tp_setattro*/
0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_BASE_EXC_SUBCLASS, /*tp_flags*/
PyDoc_STR("Common base class for all exceptions"), /* tp_doc */
(traverseproc)BaseException_traverse, /* tp_traverse */
(inquiry)BaseException_clear, /* tp_clear */
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 31d8130..932b616 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -1115,7 +1115,8 @@ PyTypeObject PyInt_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_INT_SUBCLASS, /* tp_flags */
int_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 3108ab4..0cb1a85 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2683,7 +2683,7 @@ PyTypeObject PyList_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_BASETYPE | Py_TPFLAGS_LIST_SUBCLASS, /* tp_flags */
list_doc, /* tp_doc */
(traverseproc)list_traverse, /* tp_traverse */
(inquiry)list_clear, /* tp_clear */
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 834e2c2..22d4741 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3643,7 +3643,8 @@ PyTypeObject PyLong_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_LONG_SUBCLASS, /* tp_flags */
long_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 5f6d0a6..d772e74 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1131,8 +1131,7 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
much time, since Py_NE is rarely used. */
if (a->ob_size == b->ob_size
&& (a->ob_sval[0] == b->ob_sval[0]
- && memcmp(a->ob_sval, b->ob_sval,
- a->ob_size) == 0)) {
+ && memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0)) {
result = Py_True;
} else {
result = Py_False;
@@ -1145,7 +1144,7 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
if (c==0)
c = memcmp(a->ob_sval, b->ob_sval, min_len);
- }else
+ } else
c = 0;
if (c == 0)
c = (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
@@ -4018,7 +4017,8 @@ PyTypeObject PyString_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&string_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_STRING_SUBCLASS, /* tp_flags */
string_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
@@ -4981,6 +4981,7 @@ void _Py_ReleaseInternedStrings(void)
PyObject *keys;
PyStringObject *s;
Py_ssize_t i, n;
+ Py_ssize_t immortal_size = 0, mortal_size = 0;
if (interned == NULL || !PyDict_Check(interned))
return;
@@ -4995,8 +4996,9 @@ void _Py_ReleaseInternedStrings(void)
give them their stolen references back, and then clear and DECREF
the interned dict. */
- fprintf(stderr, "releasing interned strings\n");
n = PyList_GET_SIZE(keys);
+ fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n",
+ n);
for (i = 0; i < n; i++) {
s = (PyStringObject *) PyList_GET_ITEM(keys, i);
switch (s->ob_sstate) {
@@ -5005,15 +5007,20 @@ void _Py_ReleaseInternedStrings(void)
break;
case SSTATE_INTERNED_IMMORTAL:
s->ob_refcnt += 1;
+ immortal_size += s->ob_size;
break;
case SSTATE_INTERNED_MORTAL:
s->ob_refcnt += 2;
+ mortal_size += s->ob_size;
break;
default:
Py_FatalError("Inconsistent interned string state.");
}
s->ob_sstate = SSTATE_NOT_INTERNED;
}
+ fprintf(stderr, "total size of all interned strings: "
+ "%" PY_FORMAT_SIZE_T "d/%" PY_FORMAT_SIZE_T "d "
+ "mortal/immortal\n", mortal_size, immortal_size);
Py_DECREF(keys);
PyDict_Clear(interned);
Py_DECREF(interned);
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index c85b35a..dacc3ee 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -669,7 +669,7 @@ PyTypeObject PyTuple_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TUPLE_SUBCLASS, /* tp_flags */
tuple_doc, /* tp_doc */
(traverseproc)tupletraverse, /* tp_traverse */
0, /* tp_clear */
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 848203e..e626a17 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2205,7 +2205,7 @@ PyTypeObject PyType_Type = {
(setattrofunc)type_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS, /* tp_flags */
type_doc, /* tp_doc */
(traverseproc)type_traverse, /* tp_traverse */
(inquiry)type_clear, /* tp_clear */
@@ -2874,6 +2874,24 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
COPYVAL(tp_itemsize);
COPYVAL(tp_weaklistoffset);
COPYVAL(tp_dictoffset);
+
+ /* Setup fast subclass flags */
+ if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException))
+ type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyType_Type))
+ type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyLong_Type))
+ type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyString_Type))
+ type->tp_flags |= Py_TPFLAGS_STRING_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyUnicode_Type))
+ type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyTuple_Type))
+ type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyList_Type))
+ type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS;
+ else if (PyType_IsSubtype(base, &PyDict_Type))
+ type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
}
/* Map rich comparison operators to their __xx__ namesakes */
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index fbff31b..4fe4d10 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7971,7 +7971,8 @@ PyTypeObject PyUnicode_Type = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&unicode_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */
unicode_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */