Skip to content

Commit 313886e

Browse files
committed
ext/gmp: Refactor op overloading for ZEND_BW_NOT
The only way for the do_operation object handler to be called for unary operations is when the zval is an object. Therefore we know we have a zval of the correct type and there is no need to check for it.
1 parent 7e1d035 commit 313886e

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

ext/gmp/gmp.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ typeof_op_failure: ;
404404

405405
static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1, zval *op2) /* {{{ */
406406
{
407-
mpz_ptr gmp_op1, gmp_result;
407+
mpz_ptr gmp_result;
408408
switch (opcode) {
409409
case ZEND_ADD:
410410
return binop_operator_helper(mpz_add, result, op1, op2);
@@ -429,11 +429,9 @@ static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1,
429429
case ZEND_BW_XOR:
430430
return binop_operator_helper(mpz_xor, result, op1, op2);
431431
case ZEND_BW_NOT: {
432-
if (!gmp_zend_parse_arg_into_mpz_ex(op1, &gmp_op1, 1, false)) {
433-
return FAILURE;
434-
}
432+
ZEND_ASSERT(Z_TYPE_P(op1) == IS_OBJECT && Z_OBJCE_P(op1) == gmp_ce);
435433
gmp_create(result, &gmp_result);
436-
mpz_com(gmp_result, gmp_op1);
434+
mpz_com(gmp_result, GET_GMP_FROM_ZVAL(op1));
437435
return SUCCESS;
438436
}
439437

0 commit comments

Comments
 (0)