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
00e9886b
Kaydet (Commit)
00e9886b
authored
Mar 08, 2013
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add PyDict_SetDefault. (closes #17327)
Patch by Stefan Behnel and I.
üst
763edc1c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
11 deletions
+41
-11
dict.rst
Doc/c-api/dict.rst
+9
-0
refcounts.dat
Doc/data/refcounts.dat
+5
-0
dictobject.h
Include/dictobject.h
+2
-0
NEWS
Misc/NEWS
+2
-0
dictobject.c
Objects/dictobject.c
+23
-11
No files found.
Doc/c-api/dict.rst
Dosyayı görüntüle @
00e9886b
...
...
@@ -110,6 +110,15 @@ Dictionary Objects
:c:type:`char\*`, rather than a :c:type:`PyObject\*`.
.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default)
This is the same the Python-level :meth:`dict.setdefault`. If present, it
returns the value corresponding to *key* from the dictionary *p*. If the key
is not in the dict, it is inserted with value *defaultobj* and *defaultobj*
is inserted. This function evaluates the hash function of *key* only once,
instead of evaluating it independently for the lookup and the insertion.
.. c:function:: PyObject* PyDict_Items(PyObject *p)
Return a :c:type:`PyListObject` containing all the items from the dictionary.
...
...
Doc/data/refcounts.dat
Dosyayı görüntüle @
00e9886b
...
...
@@ -220,6 +220,11 @@ PyDict_GetItemString:PyObject*::0:
PyDict_GetItemString:PyObject*:p:0:
PyDict_GetItemString:char*:key::
PyDict_SetDefault:PyObject*::0:
PyDict_SetDefault:PyObject*:p:0:
PyDict_SetDefault:PyObject*:key:0:conditionally +1 if inserted into the dict
PyDict_SetDefault:PyObject*:default:0:conditionally +1 if inserted into the dict
PyDict_Items:PyObject*::+1:
PyDict_Items:PyObject*:p:0:
...
...
Include/dictobject.h
Dosyayı görüntüle @
00e9886b
...
...
@@ -53,6 +53,8 @@ PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
PyAPI_FUNC
(
PyObject
*
)
PyDict_GetItemWithError
(
PyObject
*
mp
,
PyObject
*
key
);
PyAPI_FUNC
(
PyObject
*
)
_PyDict_GetItemIdWithError
(
PyObject
*
dp
,
struct
_Py_Identifier
*
key
);
PyAPI_FUNC
(
PyObject
*
)
PyDict_SetDefault
(
PyObject
*
mp
,
PyObject
*
key
,
PyObject
*
defaultobj
);
PyAPI_FUNC
(
int
)
PyDict_SetItem
(
PyObject
*
mp
,
PyObject
*
key
,
PyObject
*
item
);
PyAPI_FUNC
(
int
)
PyDict_DelItem
(
PyObject
*
mp
,
PyObject
*
key
);
PyAPI_FUNC
(
void
)
PyDict_Clear
(
PyObject
*
mp
);
...
...
Misc/NEWS
Dosyayı görüntüle @
00e9886b
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
-----------------
- Issue #17327: Add PyDict_SetDefault.
- Issue #17032: The "global" in the "NameError: global name '
x
' is not defined"
error message has been removed. Patch by Ram Rachum.
...
...
Objects/dictobject.c
Dosyayı görüntüle @
00e9886b
...
...
@@ -2211,19 +2211,19 @@ dict_get(register PyDictObject *mp, PyObject *args)
return
val
;
}
static
PyObject
*
dict_setdefault
(
register
PyDictObject
*
mp
,
PyObject
*
args
)
PyObject
*
PyDict_SetDefault
(
PyObject
*
d
,
PyObject
*
key
,
PyObject
*
defaultobj
)
{
PyObject
*
key
;
PyObject
*
failobj
=
Py_None
;
PyDictObject
*
mp
=
(
PyDictObject
*
)
d
;
PyObject
*
val
=
NULL
;
Py_hash_t
hash
;
PyDictKeyEntry
*
ep
;
PyObject
**
value_addr
;
if
(
!
PyArg_UnpackTuple
(
args
,
"setdefault"
,
1
,
2
,
&
key
,
&
failobj
))
if
(
!
PyDict_Check
(
d
))
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
(
!
PyUnicode_CheckExact
(
key
)
||
(
hash
=
((
PyASCIIObject
*
)
key
)
->
hash
)
==
-
1
)
{
hash
=
PyObject_Hash
(
key
);
...
...
@@ -2241,20 +2241,32 @@ dict_setdefault(register PyDictObject *mp, PyObject *args)
return
NULL
;
ep
=
find_empty_slot
(
mp
,
key
,
hash
,
&
value_addr
);
}
Py_INCREF
(
fail
obj
);
Py_INCREF
(
default
obj
);
Py_INCREF
(
key
);
MAINTAIN_TRACKING
(
mp
,
key
,
fail
obj
);
MAINTAIN_TRACKING
(
mp
,
key
,
default
obj
);
ep
->
me_key
=
key
;
ep
->
me_hash
=
hash
;
*
value_addr
=
fail
obj
;
val
=
fail
obj
;
*
value_addr
=
default
obj
;
val
=
default
obj
;
mp
->
ma_keys
->
dk_usable
--
;
mp
->
ma_used
++
;
}
Py_INCREF
(
val
);
return
val
;
}
static
PyObject
*
dict_setdefault
(
PyDictObject
*
mp
,
PyObject
*
args
)
{
PyObject
*
key
,
*
val
;
PyObject
*
defaultobj
=
Py_None
;
if
(
!
PyArg_UnpackTuple
(
args
,
"setdefault"
,
1
,
2
,
&
key
,
&
defaultobj
))
return
NULL
;
val
=
PyDict_SetDefault
(
mp
,
key
,
defaultobj
);
Py_XINCREF
(
val
);
return
val
;
}
static
PyObject
*
dict_clear
(
register
PyDictObject
*
mp
)
...
...
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