Skip to content

Add duplicate keyword argument error #1407

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

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

vazrupe
Copy link
Contributor

@vazrupe vazrupe commented Sep 23, 2019

Fixes #116

@@ -6,9 +6,19 @@ type FunctionArgument = (Option<Option<String>>, ast::Expression);
pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList, LexicalError> {
let mut args = vec![];
let mut keywords = vec![];

let mut keyword_names = vec![];
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a set like object instead of a vector would gain a speedup for larger amounts of arguments. The contains method for Vec is likely O(n) while the contains method (or equivalent method) on set like types is O(1).

Copy link
Contributor

@dralley dralley Sep 25, 2019

Choose a reason for hiding this comment

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

Might be worthwhile to use <collection>::with_capacity(func_args.len()) to avoid having lots of small allocations as they get added to the collection, regardless of whether HashMap or Vec is used.

Edit: however that might use a bit more memory sometimes. Perhaps premature optimization until someone can get around to doing measurement.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d1eaab59dcae1ee483e992e19f819c91

Copy link
Contributor

Choose a reason for hiding this comment

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

The vector re-allocation scheme is actually pretty good in rust. The amount of memory is roughly doubled, so capacity will grow something like this: 1, 2, 4, 8, 16 etc.. This results in few allocations.

@windelbouwman
Copy link
Contributor

The travis build is failing. Could you look into this? You also might want to rebase upon the master branch, since the azure build is fixed in there.

@windelbouwman windelbouwman merged commit 215eefe into RustPython:master Sep 27, 2019
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.

Duplicate keyword arguments should be a SyntaxError
3 participants