Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1f1a34c3
Unverified
Kaydet (Commit)
1f1a34c3
authored
7 years ago
tarafından
Antoine Pitrou
Kaydeden (comit)
GitHub
7 years ago
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32379: Faster MRO computation for single inheritance (#4932)
* bpo-32379: Faster MRO computation for single inheritance
üst
776407fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
4 deletions
+43
-4
test_descr.py
Lib/test/test_descr.py
+6
-0
2017-12-19-21-14-41.bpo-32379.B7mOmI.rst
...ore and Builtins/2017-12-19-21-14-41.bpo-32379.B7mOmI.rst
+1
-0
typeobject.c
Objects/typeobject.c
+36
-4
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
1f1a34c3
...
...
@@ -1783,6 +1783,12 @@ order (MRO) for bases """
def f(self): return "C"
class D(B, C):
pass
self.assertEqual(A.mro(), [A, object])
self.assertEqual(A.__mro__, (A, object))
self.assertEqual(B.mro(), [B, A, object])
self.assertEqual(B.__mro__, (B, A, object))
self.assertEqual(C.mro(), [C, A, object])
self.assertEqual(C.__mro__, (C, A, object))
self.assertEqual(D.mro(), [D, B, C, A, object])
self.assertEqual(D.__mro__, (D, B, C, A, object))
self.assertEqual(D().f(), "C")
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS.d/next/Core and Builtins/2017-12-19-21-14-41.bpo-32379.B7mOmI.rst
0 → 100644
Dosyayı görüntüle @
1f1a34c3
Make MRO computation faster when a class inherits from a single base.
This diff is collapsed.
Click to expand it.
Objects/typeobject.c
Dosyayı görüntüle @
1f1a34c3
...
...
@@ -1761,6 +1761,36 @@ mro_implementation(PyTypeObject *type)
return NULL;
}
bases = type->tp_bases;
n = PyTuple_GET_SIZE(bases);
if (n == 1) {
/* Fast path: if there is a single base, constructing the MRO
* is trivial.
*/
PyTypeObject *base = (PyTypeObject *)PyTuple_GET_ITEM(bases, 0);
Py_ssize_t k;
if (base->tp_mro == NULL) {
PyErr_Format(PyExc_TypeError,
"Cannot extend an incomplete type '%.100s'",
base->tp_name);
return NULL;
}
k = PyTuple_GET_SIZE(base->tp_mro);
result = PyTuple_New(k + 1);
if (result == NULL) {
return NULL;
}
Py_INCREF(type);
PyTuple_SET_ITEM(result, 0, (PyObject *) type);
for (i = 0; i < k; i++) {
PyObject *cls = PyTuple_GET_ITEM(base->tp_mro, i);
Py_INCREF(cls);
PyTuple_SET_ITEM(result, i + 1, cls);
}
return result;
}
/* Find a superclass linearization that honors the constraints
of the explicit lists of bases and the constraints implied by
each base class.
...
...
@@ -1770,9 +1800,6 @@ mro_implementation(PyTypeObject *type)
to_merge is the declared list of bases.
*/
bases = type->tp_bases;
n = PyTuple_GET_SIZE(bases);
to_merge = PyList_New(n+1);
if (to_merge == NULL)
return NULL;
...
...
@@ -1830,7 +1857,12 @@ static PyObject *
type_mro_impl(PyTypeObject *self)
/*[clinic end generated code: output=bffc4a39b5b57027 input=28414f4e156db28d]*/
{
return mro_implementation(self);
PyObject *seq;
seq = mro_implementation(self);
if (seq != NULL && !PyList_Check(seq)) {
Py_SETREF(seq, PySequence_List(seq));
}
return seq;
}
static int
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment