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
88ea166d
Commit
88ea166d
authored
Aug 29, 2019
by
Raymond Hettinger
Committed by
GitHub
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-8425: Fast path for set inplace difference when the second set is large (GH-15590)
parent
4901fe27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
Misc/NEWS.d/next/Core and Builtins/2019-08-29-01-55-38.bpo-8425.FTq4A8.rst
...Core and Builtins/2019-08-29-01-55-38.bpo-8425.FTq4A8.rst
+3
-0
Objects/setobject.c
Objects/setobject.c
+17
-1
No files found.
Misc/NEWS.d/next/Core and Builtins/2019-08-29-01-55-38.bpo-8425.FTq4A8.rst
0 → 100644
View file @
88ea166d
Optimize set difference_update for the case when the other set is much
larger than the base set. (Suggested by Evgeny Kapun with code contributed
by Michele Orrù).
Objects/setobject.c
View file @
88ea166d
...
...
@@ -1463,9 +1463,25 @@ set_difference_update_internal(PySetObject *so, PyObject *other)
setentry
*
entry
;
Py_ssize_t
pos
=
0
;
/* Optimization: When the other set is more than 8 times
larger than the base set, replace the other set with
interesection of the two sets.
*/
if
((
PySet_GET_SIZE
(
other
)
>>
3
)
>
PySet_GET_SIZE
(
so
))
{
other
=
set_intersection
(
so
,
other
);
if
(
other
==
NULL
)
return
-
1
;
}
else
{
Py_INCREF
(
other
);
}
while
(
set_next
((
PySetObject
*
)
other
,
&
pos
,
&
entry
))
if
(
set_discard_entry
(
so
,
entry
->
key
,
entry
->
hash
)
<
0
)
if
(
set_discard_entry
(
so
,
entry
->
key
,
entry
->
hash
)
<
0
)
{
Py_DECREF
(
other
);
return
-
1
;
}
Py_DECREF
(
other
);
}
else
{
PyObject
*
key
,
*
it
;
it
=
PyObject_GetIter
(
other
);
...
...
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