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

Improve logic and performance #1228

Merged
merged 1 commit into from
Dec 9, 2022
Merged

Conversation

jmishra01
Copy link
Contributor

Refactor some code in utils file for better performance.

init = [[x] for x in lists[0]]
return reduce(lambda a,b: [i+[j] for i in a for j in b], lists[1:], init)

return list(product(*lists))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For combine_alternatives method, more cleaner approach.
image

lark/utils.py Outdated
else:
false_elems.append(elem)

true_elems = [elem for elem in seq if pred(elem) or false_elems.append(elem)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Performance improve, if use list comprehension. Please check attached file.
image

@jmishra01 jmishra01 force-pushed the lark-utils branch 2 times, most recently from 7b0f809 to de37fae Compare December 7, 2022 05:53
@erezsh
Copy link
Member

erezsh commented Dec 9, 2022

Looks good to me. @MegaIng , any objections?

@erezsh erezsh merged commit ed2bd92 into lark-parser:master Dec 9, 2022
@erezsh
Copy link
Member

erezsh commented Dec 9, 2022

@jmishra01 Thanks for contributing!

I hope it was more fun than painful 😄

@jmishra01 jmishra01 deleted the lark-utils branch December 9, 2022 16:09
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.

3 participants