-
Notifications
You must be signed in to change notification settings - Fork 878
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
Optimized fuzz.py #136
Open
rahul-nath
wants to merge
4
commits into
seatgeek:master
Choose a base branch
from
rahul-nath:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Optimized fuzz.py #136
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4e99380
Optimized some lines for logic in fuzz.py
rahul-nath 16253c2
Optimized some lines for logic in fuzz.py
rahul-nath b6ecd93
misplaced bracket, fixed syntax error in fuzz.py
rahul-nath ea04471
...different misplaced bracket...fixed syntax error in fuzz.py
rahul-nath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,9 +146,7 @@ def _token_set(s1, s2, partial=True, force_ascii=True, full_process=True): | |
p1 = utils.full_process(s1, force_ascii=force_ascii) if full_process else s1 | ||
p2 = utils.full_process(s2, force_ascii=force_ascii) if full_process else s2 | ||
|
||
if not utils.validate_string(p1): | ||
return 0 | ||
if not utils.validate_string(p2): | ||
if not (utils.validate_string(p1) and utils.validate_string(p2)): | ||
return 0 | ||
|
||
# pull tokens | ||
|
@@ -159,17 +157,10 @@ def _token_set(s1, s2, partial=True, force_ascii=True, full_process=True): | |
diff1to2 = tokens1.difference(tokens2) | ||
diff2to1 = tokens2.difference(tokens1) | ||
|
||
sorted_sect = " ".join(sorted(intersection)) | ||
sorted_1to2 = " ".join(sorted(diff1to2)) | ||
sorted_2to1 = " ".join(sorted(diff2to1)) | ||
|
||
combined_1to2 = sorted_sect + " " + sorted_1to2 | ||
combined_2to1 = sorted_sect + " " + sorted_2to1 | ||
|
||
# strip | ||
sorted_sect = sorted_sect.strip() | ||
combined_1to2 = combined_1to2.strip() | ||
combined_2to1 = combined_2to1.strip() | ||
# sort, join, and strip | ||
sorted_sect = (" ".join(sorted(intersection))).strip() | ||
combined_1to2 = (" ".join([sorted_sect, " ".join(sorted(diff1to2))])).strip() | ||
combined_2to1 = " ".join([sorted_sect, " ".join(sorted(diff2to1))]).strip() | ||
|
||
if partial: | ||
ratio_func = partial_ratio | ||
|
@@ -202,9 +193,7 @@ def QRatio(s1, s2, force_ascii=True): | |
p1 = utils.full_process(s1, force_ascii=force_ascii) | ||
p2 = utils.full_process(s2, force_ascii=force_ascii) | ||
|
||
if not utils.validate_string(p1): | ||
return 0 | ||
if not utils.validate_string(p2): | ||
if not (utils.validate_string(p1) and utils.validate_string(p2)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again no performance implication. Simply a preference, whether these two if statements should be joined |
||
return 0 | ||
|
||
return ratio(p1, p2) | ||
|
@@ -223,9 +212,7 @@ def WRatio(s1, s2, force_ascii=True): | |
p1 = utils.full_process(s1, force_ascii=force_ascii) | ||
p2 = utils.full_process(s2, force_ascii=force_ascii) | ||
|
||
if not utils.validate_string(p1): | ||
return 0 | ||
if not utils.validate_string(p2): | ||
if not (utils.validate_string(p1) and utils.validate_string(p2)): | ||
return 0 | ||
|
||
# should we look at partials? | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty much the same, but not completely. In this changed code whitespace from
sorted_sect
is stripped before the strings are combined, while it was done afterwards in the original code. This does not matter in this case, since the original strip forsorted_sect
was not required, since" ".join(sorted(intersection))
can never have whitespaces in begin or end. From a performance standpoint this does not really matter, but is probably slightly slower, since it creates some intermediate lists and calls the join function more often.