Skip to content
Prev Previous commit
Next Next commit
Apply feedback from code review
  • Loading branch information
brandtbucher committed Nov 9, 2021
commit 4cac17a4c9557d8c9833b2fdf2c5845f72039223
6 changes: 5 additions & 1 deletion Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,9 @@ static const nb_slot_info nb_slot_infos[] = {
#undef NB_SLOT_INFO

typedef struct {
const char name[3];
// We only really need 3 characters for name, but we're using 4 here to
// avoid having an awkward 7-byte structure:
const char name[4];
const char iname[4];
} nb_name_info;

Expand All @@ -1760,12 +1762,14 @@ static const nb_name_info nb_name_infos[] = {
PyObject *
_PyNumber_Op(PyObject *o1, PyObject *o2, unsigned op)
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.

This just forwards to binary_op. You might want to consider:

  1. Make this the function that does the work (effectively inlining binary_op here).
  2. Make the old API PyNumber_TrueDivide, etc. call _PyNumber_Op
  3. Delete binary_op.

{
// TODO: Just convert binary_op to _PyNumber_Op!
return binary_op(o1, o2, nb_slot_infos[op].slot, nb_name_infos[op].name);
}

PyObject *
_PyNumber_InPlaceOp(PyObject *o1, PyObject *o2, unsigned op)
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.

Same comment as for _PyNumber_Op.

{
// TODO: Just convert binary_iop to _PyNumber_InPlaceOp!
return binary_iop(o1, o2, nb_slot_infos[op].islot, nb_slot_infos[op].slot,
nb_name_infos[op].iname);
}
Expand Down