py/modbuiltins: Implement abs() by dispatching to MP_UNARY_OP_ABS.
This allows user classes to implement __abs__ special method, and saves code size (104 bytes for x86_64), even though during refactor, an issue was fixed and few optimizations were made: * abs() of minimum (negative) small int value is calculated properly. * objint_longlong and objint_mpz avoid allocating new object is the argument is already non-negative.
This commit is contained in:
@@ -50,6 +50,7 @@ typedef enum {
|
||||
MP_UNARY_OP_NEGATIVE,
|
||||
MP_UNARY_OP_INVERT,
|
||||
MP_UNARY_OP_NOT,
|
||||
MP_UNARY_OP_ABS, // __abs__
|
||||
MP_UNARY_OP_SIZEOF, // for sys.getsizeof()
|
||||
} mp_unary_op_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user