Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvement in Regex.__init__ #73

Closed
wants to merge 1 commit into from
Closed

minor improvement in Regex.__init__ #73

wants to merge 1 commit into from

Conversation

SergBobrovsky
Copy link

No description provided.

@mildebrandt
Copy link

Hi, thanks for your interest in Yamale. Can you describe what improvement this makes? If it's a performance improvement, can you provide some numbers to go along with this? Thanks!

flags = 0
for k, v in util.get_iter(self._regex_flags):
flags |= v if kwargs.pop(k, False) else 0
flags = sum(v for k, v in util.get_iter(self._regex_flags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code uses a "bitwise or", it is not the same as using sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for watching @drmull :) In this case, it should be fine since they're defined as ints anyway, and the flags won't overlap:

SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking)
SRE_FLAG_IGNORECASE = 2 # case insensitive
SRE_FLAG_LOCALE = 4 # honour system locale
SRE_FLAG_MULTILINE = 8 # treat target as multiline string
SRE_FLAG_DOTALL = 16 # treat target as a single string
SRE_FLAG_UNICODE = 32 # use unicode "locale"
SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments
SRE_FLAG_DEBUG = 128 # debugging
SRE_FLAG_ASCII = 256 # use ascii "locale"

But I'm not a fan of change for the sake of change, so I was curious if this solved a problem I wasn't aware of before.

Copy link
Contributor

@abourree abourree Jan 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer "bitwise or" if same flag can occur many time: SRE_FLAG_TEMPLATE twice become SRE_FLAG_IGNORE_CASE with "sum"

@mildebrandt
Copy link

This PR doesn't add any obvious improvements.

@mildebrandt mildebrandt closed this Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants