Message413075
If the argument of set.issuperset() is not a set, it is first converted to a set. It is equivalent to the following code:
if not isinstance(other, (set, frozenset)):
other = set(other)
# The following is equivalent to:
# return set.issubset(other, self)
for x in other:
if x not in self
return False
return True
Two drawbacks of this algorithm:
1. It creates a new set, which takes O(len(other)) time and consumes O(len(set(other))) memory.
2. It needs to iterate other to the end, even if the result is known earlier.
The proposed PR straightforward the code. The C code is now larger, but it no longer need additional memory, performs less operations and can stop earlier. |
|
| Date |
User |
Action |
Args |
| 2022-02-11 15:15:23 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger |
| 2022-02-11 15:15:23 | serhiy.storchaka | set | messageid: <1644592523.91.0.460084742995.issue46721@roundup.psfhosted.org> |
| 2022-02-11 15:15:23 | serhiy.storchaka | link | issue46721 messages |
| 2022-02-11 15:15:23 | serhiy.storchaka | create | |
|