-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-34925: Optimize common case for bisect() argument parsing #9753
Conversation
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.
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 |
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.
Perhaps you meant Py_LOCAL_INLINE(Py_ssize_t)
?
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.
Is that being used anymore? I believe we're using "inline" directly (and some other C99 features) nowadays.
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.
I don't know. Maybe Py_LOCAL_INLINE
is outdated.
It is expanded to a different form on MSVC.
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) { |
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.
Sorry for be pedantic, but could you please add spaces around ==
for conforming PEP 7? Without spaces the code looks sloppy to me.
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.
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.
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.
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.
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 { |
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.
For PEP 7 }
and else {
should be on separate lines.
}
else {
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.
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.
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.
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: Please replace |
https://bugs.python.org/issue34925