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
88a9cd9b
Kaydet (Commit)
88a9cd9b
authored
Kas 19, 2013
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #19513: repr(tuple) now uses _PyUnicodeWriter for better performances
üst
4a58707a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
27 deletions
+37
-27
tupleobject.c
Objects/tupleobject.c
+37
-27
No files found.
Objects/tupleobject.c
Dosyayı görüntüle @
88a9cd9b
...
...
@@ -255,20 +255,12 @@ static PyObject *
tuplerepr
(
PyTupleObject
*
v
)
{
Py_ssize_t
i
,
n
;
PyObject
*
s
=
NULL
;
_PyAccu
acc
;
static
PyObject
*
sep
=
NULL
;
_PyUnicodeWriter
writer
;
n
=
Py_SIZE
(
v
);
if
(
n
==
0
)
return
PyUnicode_FromString
(
"()"
);
if
(
sep
==
NULL
)
{
sep
=
PyUnicode_FromString
(
", "
);
if
(
sep
==
NULL
)
return
NULL
;
}
/* While not mutable, it is still possible to end up with a cycle in a
tuple through an object that stores itself within a tuple (and thus
infinitely asks for the repr of itself). This should only be
...
...
@@ -278,40 +270,58 @@ tuplerepr(PyTupleObject *v)
return
i
>
0
?
PyUnicode_FromString
(
"(...)"
)
:
NULL
;
}
if
(
_PyAccu_Init
(
&
acc
))
goto
error
;
_PyUnicodeWriter_Init
(
&
writer
);
writer
.
overallocate
=
1
;
if
(
Py_SIZE
(
v
)
>
1
)
{
/* "(" + "1" + ", 2" * (len - 1) + ")" */
writer
.
min_length
=
1
+
1
+
(
2
+
1
)
*
(
Py_SIZE
(
v
)
-
1
)
+
1
;
}
else
{
/* "(1,)" */
writer
.
min_length
=
4
;
}
s
=
PyUnicode_FromString
(
"("
);
if
(
s
==
NULL
||
_PyAccu_Accumulate
(
&
acc
,
s
))
if
(
_PyUnicodeWriter_WriteChar
(
&
writer
,
'('
)
<
0
)
goto
error
;
Py_CLEAR
(
s
);
/* Do repr() on each element. */
for
(
i
=
0
;
i
<
n
;
++
i
)
{
PyObject
*
s
;
if
(
i
>
0
)
{
if
(
_PyUnicodeWriter_WriteASCIIString
(
&
writer
,
", "
,
2
)
<
0
)
goto
error
;
}
if
(
Py_EnterRecursiveCall
(
" while getting the repr of a tuple"
))
goto
error
;
s
=
PyObject_Repr
(
v
->
ob_item
[
i
]);
Py_LeaveRecursiveCall
();
if
(
i
>
0
&&
_PyAccu_Accumulate
(
&
acc
,
sep
)
)
if
(
s
==
NULL
)
goto
error
;
if
(
s
==
NULL
||
_PyAccu_Accumulate
(
&
acc
,
s
))
if
(
_PyUnicodeWriter_WriteStr
(
&
writer
,
s
)
<
0
)
{
Py_DECREF
(
s
);
goto
error
;
}
Py_DECREF
(
s
);
}
writer
.
overallocate
=
0
;
if
(
n
>
1
)
{
if
(
_PyUnicodeWriter_WriteChar
(
&
writer
,
')'
)
<
0
)
goto
error
;
}
else
{
if
(
_PyUnicodeWriter_WriteASCIIString
(
&
writer
,
",)"
,
2
)
<
0
)
goto
error
;
Py_CLEAR
(
s
);
}
if
(
n
>
1
)
s
=
PyUnicode_FromString
(
")"
);
else
s
=
PyUnicode_FromString
(
",)"
);
if
(
s
==
NULL
||
_PyAccu_Accumulate
(
&
acc
,
s
))
goto
error
;
Py_CLEAR
(
s
);
Py_ReprLeave
((
PyObject
*
)
v
);
return
_Py
Accu_Finish
(
&
acc
);
return
_Py
UnicodeWriter_Finish
(
&
writer
);
error:
_PyAccu_Destroy
(
&
acc
);
Py_XDECREF
(
s
);
_PyUnicodeWriter_Dealloc
(
&
writer
);
Py_ReprLeave
((
PyObject
*
)
v
);
return
NULL
;
}
...
...
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