This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients rhettinger, serhiy.storchaka
Date 2022-02-11.15:15:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644592523.91.0.460084742995.issue46721@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-02-11 15:15:23serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger
2022-02-11 15:15:23serhiy.storchakasetmessageid: <1644592523.91.0.460084742995.issue46721@roundup.psfhosted.org>
2022-02-11 15:15:23serhiy.storchakalinkissue46721 messages
2022-02-11 15:15:23serhiy.storchakacreate