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

bpo-34925: Optimize common case for bisect() argument parsing #9753

Merged
merged 4 commits into from
Oct 8, 2018

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Oct 8, 2018

@rhettinger rhettinger added the performance Performance or resource usage label Oct 8, 2018
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Looks correct, besides few style issues.

I hope this case will be automatically optimized by Argument Clinic in 3.8.

@@ -8,7 +8,7 @@ Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru).

_Py_IDENTIFIER(insert);

static Py_ssize_t
static inline Py_ssize_t
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps you meant Py_LOCAL_INLINE(Py_ssize_t)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that being used anymore? I believe we're using "inline" directly (and some other C99 features) nowadays.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know. Maybe Py_LOCAL_INLINE is outdated.

It is expanded to a different form on MSVC.

if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|nn:bisect_right",
keywords, &list, &item, &lo, &hi))
return NULL;
if (kw==NULL && PyTuple_GET_SIZE(args)==2) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for be pedantic, but could you please add spaces around == for conforming PEP 7? Without spaces the code looks sloppy to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, when multiple terms are present, PEP 7 (and PEP 8) allow for tightening spaces on the inner terms while "adding" spaces around the outermost (lowest-priority) operators.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is allowed only for arithmetic operators like * in +.

Always put spaces around assignment, Boolean and comparison operators. In expressions using a lot of operators, add spaces around the outermost (lowest-priority) operators.

if (kw==NULL && PyTuple_GET_SIZE(args)==2) {
list = PyTuple_GET_ITEM(args, 0);
item = PyTuple_GET_ITEM(args, 1);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

For PEP 7 } and else { should be on separate lines.

    }
    else {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see that in PEP 7 but it looks weird to me. I believe we historically allowed "} else {" in multiple places in the code when that reflects how the author thinks about the code. If you insist, I'll change it, but I like it better as-is.

Copy link
Member

Choose a reason for hiding this comment

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

No, I do not insist. I added this comment just for the case if you missed this part of PEP 7 and do not have preferences. I always write this code as two lines in new and modified code, but writing it as a single line LGTM too.

The only thing looks weird to me is messed spaces around ==.

@rhettinger rhettinger merged commit de2e448 into python:master Oct 8, 2018
@bedevere-bot
Copy link

@rhettinger: Please replace # with GH- in the commit message next time. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants