Skip to content

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

Merged
rhettinger merged 4 commits into
python:masterfrom
rhettinger:bisect_argument_optimization
Oct 8, 2018
Merged

bpo-34925: Optimize common case for bisect() argument parsing#9753
rhettinger merged 4 commits into
python:masterfrom
rhettinger:bisect_argument_optimization

Conversation

@rhettinger

@rhettinger rhettinger commented Oct 8, 2018

Copy link
Copy Markdown
Contributor

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

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Modules/_bisectmodule.c
_Py_IDENTIFIER(insert);

static Py_ssize_t
static inline Py_ssize_t

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Modules/_bisectmodule.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Modules/_bisectmodule.c Outdated
if (kw==NULL && PyTuple_GET_SIZE(args)==2) {
list = PyTuple_GET_ITEM(args, 0);
item = PyTuple_GET_ITEM(args, 1);
} else {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

@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