Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d2962f14
Commit
d2962f14
authored
Feb 08, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25949: __dict__ for an OrderedDict instance is now created only when
needed.
parent
79ad8970
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
17 deletions
+13
-17
Lib/test/test_ordered_dict.py
Lib/test/test_ordered_dict.py
+3
-1
Misc/NEWS
Misc/NEWS
+3
-0
Objects/odictobject.c
Objects/odictobject.c
+7
-16
No files found.
Lib/test/test_ordered_dict.py
View file @
d2962f14
...
...
@@ -298,9 +298,11 @@ class OrderedDictTests:
# do not save instance dictionary if not needed
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
od
=
OrderedDict
(
pairs
)
self
.
assertIsInstance
(
od
.
__dict__
,
dict
)
self
.
assertIsNone
(
od
.
__reduce__
()[
2
])
od
.
x
=
10
self
.
assertIsNotNone
(
od
.
__reduce__
()[
2
])
self
.
assertEqual
(
od
.
__dict__
[
'x'
],
10
)
self
.
assertEqual
(
od
.
__reduce__
()[
2
],
{
'x'
:
10
})
def
test_pickle_recursive
(
self
):
OrderedDict
=
self
.
OrderedDict
...
...
Misc/NEWS
View file @
d2962f14
...
...
@@ -170,6 +170,9 @@ Core and Builtins
Library
-------
-
Issue
#
25949
:
__dict__
for
an
OrderedDict
instance
is
now
created
only
when
needed
.
-
Issue
#
25911
:
Restored
support
of
bytes
paths
in
os
.
walk
()
on
Windows
.
-
Issue
#
26045
:
Add
UTF
-
8
suggestion
to
error
message
when
posting
a
...
...
Objects/odictobject.c
View file @
d2962f14
...
...
@@ -1424,14 +1424,13 @@ static PyMethodDef odict_methods[] = {
* OrderedDict members
*/
/* tp_
members
*/
/* tp_
getset
*/
static
Py
MemberDef
odict_members
[]
=
{
{
"__dict__"
,
T_OBJECT
,
offsetof
(
PyODictObject
,
od_inst_dict
),
READONLY
},
{
0
}
static
Py
GetSetDef
odict_getset
[]
=
{
{
"__dict__"
,
PyObject_GenericGetDict
,
PyObject_GenericSetDict
},
{
NULL
}
};
/* ----------------------------------------------
* OrderedDict type slot methods
*/
...
...
@@ -1653,20 +1652,12 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds)
static
PyObject
*
odict_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
dict
;
PyODictObject
*
od
;
dict
=
PyDict_New
();
if
(
dict
==
NULL
)
return
NULL
;
od
=
(
PyODictObject
*
)
PyDict_Type
.
tp_new
(
type
,
args
,
kwds
);
if
(
od
==
NULL
)
{
Py_DECREF
(
dict
);
if
(
od
==
NULL
)
return
NULL
;
}
od
->
od_inst_dict
=
dict
;
/* type constructor fills the memory with zeros (see
PyType_GenericAlloc()), there is no need to set them to zero again */
if
(
_odict_resize
(
od
)
<
0
)
{
...
...
@@ -1708,8 +1699,8 @@ PyTypeObject PyODict_Type = {
(
getiterfunc
)
odict_iter
,
/* tp_iter */
0
,
/* tp_iternext */
odict_methods
,
/* tp_methods */
odict_members
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_members */
odict_getset
,
/* tp_getset */
&
PyDict_Type
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
...
...
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