This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When one creates all possible combos of an IntFlag, e.g. with
from enum import Flag
F = Flag("F", list("abcdefghijklm"))
for idx in range(2**len(F) - 1):
F(idx)
the previous version would exhibit quadratic complexity because _value2member_map_ would grow bigger over each iteration.
Iterate over "true" flag members rather than _value2member_map_,
to avoid this problem. For a 13-member flag (so 8192 combinations),
the speedup is more than 100x.
When one creates all possible combos of an IntFlag, e.g. with
from enum import Flag
F = Flag("F", list("abcdefghijklm"))
for idx in range(2**len(F) - 1):
F(idx)
the previous version would exhibit quadratic complexity because
_value2member_map_ would grow bigger over each iteration.
Iterate over "true" flag members rather than _value2member_map_,
to avoid this problem. For a 13-member flag (so 8192 combinations),
the speedup is more than 100x.
I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).
Recognized GitHub username
We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:
This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.
You can check yourself to see if the CLA has been received.
Thanks again for the contribution, we look forward to reviewing it!
Your patch fixes the problem with Flag, but not with IntFlag (replace Flag by IntFlag in the original example and the slow behavior still exists with your patch, but not with mine).
@anntzer Thanks for your response. You are right. The previous commit did not resolve IntFlag, but I think there are still ways to solve Flag and IntFlag without creating members. So I create another commit, see in hongweipeng@9ae31f4 .
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When one creates all possible combos of an IntFlag, e.g. with
the previous version would exhibit quadratic complexity because
_value2member_map_would grow bigger over each iteration.Iterate over "true" flag members rather than
_value2member_map_,to avoid this problem. For a 13-member flag (so 8192 combinations),
the speedup is more than 100x.
https://bugs.python.org/issue38045