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
f91929b1
Kaydet (Commit)
f91929b1
authored
Kas 19, 2013
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #19646: repr(dict) now uses _PyUnicodeWriter API for better performances
üst
88a9cd9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
55 deletions
+54
-55
dictobject.c
Objects/dictobject.c
+54
-55
No files found.
Objects/dictobject.c
Dosyayı görüntüle @
f91929b1
...
...
@@ -1397,9 +1397,9 @@ static PyObject *
dict_repr
(
PyDictObject
*
mp
)
{
Py_ssize_t
i
;
PyObject
*
s
,
*
temp
,
*
colon
=
NULL
;
PyObject
*
pieces
=
NULL
,
*
result
=
NULL
;
PyObject
*
key
,
*
value
;
PyObject
*
key
=
NULL
,
*
value
=
NULL
;
_PyUnicodeWriter
writer
;
int
first
;
i
=
Py_ReprEnter
((
PyObject
*
)
mp
);
if
(
i
!=
0
)
{
...
...
@@ -1407,74 +1407,73 @@ dict_repr(PyDictObject *mp)
}
if
(
mp
->
ma_used
==
0
)
{
result
=
PyUnicode_FromString
(
"{}"
);
goto
Done
;
Py_ReprLeave
((
PyObject
*
)
mp
);
return
PyUnicode_FromString
(
"{}"
)
;
}
pieces
=
PyList_New
(
0
);
if
(
pieces
==
NULL
)
goto
Done
;
_PyUnicodeWriter_Init
(
&
writer
);
writer
.
overallocate
=
1
;
/* "{" + "1: 2" + ", 3: 4" * (len - 1) + "}" */
writer
.
min_length
=
1
+
4
+
(
2
+
4
)
*
(
mp
->
ma_used
-
1
)
+
1
;
colon
=
PyUnicode_FromString
(
": "
);
if
(
colon
==
NULL
)
goto
Done
;
if
(
_PyUnicodeWriter_WriteChar
(
&
writer
,
'{'
)
<
0
)
goto
error
;
/* Do repr() on each key+value pair, and insert ": " between them.
Note that repr may mutate the dict. */
i
=
0
;
first
=
1
;
while
(
PyDict_Next
((
PyObject
*
)
mp
,
&
i
,
&
key
,
&
value
))
{
int
status
;
PyObject
*
s
;
int
res
;
/* Prevent repr from deleting key or value during key format. */
Py_INCREF
(
key
);
Py_INCREF
(
value
);
if
(
!
first
)
{
if
(
_PyUnicodeWriter_WriteASCIIString
(
&
writer
,
", "
,
2
)
<
0
)
goto
error
;
}
first
=
0
;
s
=
PyObject_Repr
(
key
);
PyUnicode_Append
(
&
s
,
colon
);
if
(
s
==
NULL
)
goto
Done
;
goto
error
;
res
=
_PyUnicodeWriter_WriteStr
(
&
writer
,
s
);
Py_DECREF
(
s
);
if
(
res
<
0
)
goto
error
;
PyUnicode_AppendAndDel
(
&
s
,
PyObject_Repr
(
value
));
Py_DECREF
(
key
);
Py_DECREF
(
value
);
if
(
_PyUnicodeWriter_WriteASCIIString
(
&
writer
,
": "
,
2
)
<
0
)
goto
error
;
s
=
PyObject_Repr
(
value
);
if
(
s
==
NULL
)
goto
Done
;
status
=
PyList_Append
(
pieces
,
s
);
Py_DECREF
(
s
);
/* append created a new ref */
if
(
status
<
0
)
goto
Done
;
}
/* Add "{}" decorations to the first and last items. */
assert
(
PyList_GET_SIZE
(
pieces
)
>
0
);
s
=
PyUnicode_FromString
(
"{"
);
if
(
s
==
NULL
)
goto
Done
;
temp
=
PyList_GET_ITEM
(
pieces
,
0
);
PyUnicode_AppendAndDel
(
&
s
,
temp
);
PyList_SET_ITEM
(
pieces
,
0
,
s
);
if
(
s
==
NULL
)
goto
Done
;
s
=
PyUnicode_FromString
(
"}"
);
if
(
s
==
NULL
)
goto
Done
;
temp
=
PyList_GET_ITEM
(
pieces
,
PyList_GET_SIZE
(
pieces
)
-
1
);
PyUnicode_AppendAndDel
(
&
temp
,
s
);
PyList_SET_ITEM
(
pieces
,
PyList_GET_SIZE
(
pieces
)
-
1
,
temp
);
if
(
temp
==
NULL
)
goto
Done
;
/* Paste them all together with ", " between. */
s
=
PyUnicode_FromString
(
", "
);
if
(
s
==
NULL
)
goto
Done
;
result
=
PyUnicode_Join
(
s
,
pieces
);
Py_DECREF
(
s
);
Done
:
Py_XDECREF
(
pieces
);
Py_XDECREF
(
colon
);
goto
error
;
res
=
_PyUnicodeWriter_WriteStr
(
&
writer
,
s
);
Py_DECREF
(
s
);
if
(
res
<
0
)
goto
error
;
Py_CLEAR
(
key
);
Py_CLEAR
(
value
);
}
writer
.
overallocate
=
0
;
if
(
_PyUnicodeWriter_WriteChar
(
&
writer
,
'}'
)
<
0
)
goto
error
;
Py_ReprLeave
((
PyObject
*
)
mp
);
return
result
;
return
_PyUnicodeWriter_Finish
(
&
writer
);
error
:
Py_ReprLeave
((
PyObject
*
)
mp
);
_PyUnicodeWriter_Dealloc
(
&
writer
);
Py_XDECREF
(
key
);
Py_XDECREF
(
value
);
return
NULL
;
}
static
Py_ssize_t
...
...
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