Skip to content

Commit

Permalink
Use specialised zend_new_pair() function to return array pairs in gmp
Browse files Browse the repository at this point in the history
This is a bit faster, and more readable.
  • Loading branch information
nielsdos authored and Girgias committed Nov 27, 2024
1 parent 8addc3c commit 0833f23
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,7 @@ ZEND_FUNCTION(gmp_div_qr)
gmp_create(&result1, &gmpnum_result1);
gmp_create(&result2, &gmpnum_result2);

array_init(return_value);
add_next_index_zval(return_value, &result1);
add_next_index_zval(return_value, &result2);
RETVAL_ARR(zend_new_pair(&result1, &result2));

switch (round) {
case GMP_ROUND_ZERO:
Expand Down Expand Up @@ -1217,9 +1215,7 @@ ZEND_FUNCTION(gmp_sqrtrem)
gmp_create(&result1, &gmpnum_result1);
gmp_create(&result2, &gmpnum_result2);

array_init(return_value);
add_next_index_zval(return_value, &result1);
add_next_index_zval(return_value, &result2);
RETVAL_ARR(zend_new_pair(&result1, &result2));

mpz_sqrtrem(gmpnum_result1, gmpnum_result2, gmpnum_a);
}
Expand Down Expand Up @@ -1276,9 +1272,7 @@ ZEND_FUNCTION(gmp_rootrem)
gmp_create(&result1, &gmpnum_result1);
gmp_create(&result2, &gmpnum_result2);

array_init(return_value);
add_next_index_zval(return_value, &result1);
add_next_index_zval(return_value, &result2);
RETVAL_ARR(zend_new_pair(&result1, &result2));

#if GMP_51_OR_NEWER
/* mpz_rootrem() is supported since GMP 4.2, but buggy wrt odd roots
Expand Down

0 comments on commit 0833f23

Please sign in to comment.