diff options
| author | Mattias EngdegÄrd | 2024-07-27 14:10:40 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-07-27 14:58:59 +0200 |
| commit | 7753a597fb84ce03ebcab87ec57553a06f6327e1 (patch) | |
| tree | 32178167b6ee5da45b1a94f1260b1bfb6e8e91b6 /src/data.c | |
| parent | e5a94491170bdde62c1afa19ec86e16a07429395 (diff) | |
| download | emacs-7753a597fb84ce03ebcab87ec57553a06f6327e1.tar.gz emacs-7753a597fb84ce03ebcab87ec57553a06f6327e1.zip | |
Reduce type checks in arithcompare
* src/data.c (coerce_marker, not_number_or_marker): New.
(arithcompare): Don't use NUMBERP to check types up-front since we
are going to branch on types anyway.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/src/data.c b/src/data.c index 40b5a42b65b..d947d200870 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2682,11 +2682,23 @@ check_number_coerce_marker (Lisp_Object x) | |||
| 2682 | return x; | 2682 | return x; |
| 2683 | } | 2683 | } |
| 2684 | 2684 | ||
| 2685 | static Lisp_Object | ||
| 2686 | coerce_marker (Lisp_Object x) | ||
| 2687 | { | ||
| 2688 | return MARKERP (x) ? make_fixnum (marker_position (x)) : x; | ||
| 2689 | } | ||
| 2690 | |||
| 2691 | static AVOID | ||
| 2692 | not_number_or_marker (Lisp_Object x) | ||
| 2693 | { | ||
| 2694 | wrong_type_argument (Qnumber_or_marker_p, x); | ||
| 2695 | } | ||
| 2696 | |||
| 2685 | cmp_bits_t | 2697 | cmp_bits_t |
| 2686 | arithcompare (Lisp_Object num1, Lisp_Object num2) | 2698 | arithcompare (Lisp_Object num1, Lisp_Object num2) |
| 2687 | { | 2699 | { |
| 2688 | num1 = check_number_coerce_marker (num1); | 2700 | num1 = coerce_marker (num1); |
| 2689 | num2 = check_number_coerce_marker (num2); | 2701 | num2 = coerce_marker (num2); |
| 2690 | 2702 | ||
| 2691 | bool lt, eq, gt; | 2703 | bool lt, eq, gt; |
| 2692 | if (FLOATP (num1)) | 2704 | if (FLOATP (num1)) |
| @@ -2725,15 +2737,20 @@ arithcompare (Lisp_Object num1, Lisp_Object num2) | |||
| 2725 | gt = f1 > f2; | 2737 | gt = f1 > f2; |
| 2726 | } | 2738 | } |
| 2727 | } | 2739 | } |
| 2728 | else if (isnan (f1)) | 2740 | else if (BIGNUMP (num2)) |
| 2729 | lt = eq = gt = false; | ||
| 2730 | else | ||
| 2731 | { | 2741 | { |
| 2732 | int cmp = mpz_cmp_d (*xbignum_val (num2), f1); | 2742 | if (isnan (f1)) |
| 2733 | eq = cmp == 0; | 2743 | lt = eq = gt = false; |
| 2734 | lt = cmp > 0; | 2744 | else |
| 2735 | gt = cmp < 0; | 2745 | { |
| 2746 | int cmp = mpz_cmp_d (*xbignum_val (num2), f1); | ||
| 2747 | eq = cmp == 0; | ||
| 2748 | lt = cmp > 0; | ||
| 2749 | gt = cmp < 0; | ||
| 2750 | } | ||
| 2736 | } | 2751 | } |
| 2752 | else | ||
| 2753 | not_number_or_marker (num2); | ||
| 2737 | } | 2754 | } |
| 2738 | else if (FIXNUMP (num1)) | 2755 | else if (FIXNUMP (num1)) |
| 2739 | { | 2756 | { |
| @@ -2765,7 +2782,7 @@ arithcompare (Lisp_Object num1, Lisp_Object num2) | |||
| 2765 | lt = i1 < i2; | 2782 | lt = i1 < i2; |
| 2766 | gt = i1 > i2; | 2783 | gt = i1 > i2; |
| 2767 | } | 2784 | } |
| 2768 | else | 2785 | else if (BIGNUMP (num2)) |
| 2769 | { | 2786 | { |
| 2770 | int sgn = mpz_sgn (*xbignum_val (num2)); | 2787 | int sgn = mpz_sgn (*xbignum_val (num2)); |
| 2771 | eassume (sgn != 0); | 2788 | eassume (sgn != 0); |
| @@ -2773,35 +2790,44 @@ arithcompare (Lisp_Object num1, Lisp_Object num2) | |||
| 2773 | lt = sgn > 0; | 2790 | lt = sgn > 0; |
| 2774 | gt = sgn < 0; | 2791 | gt = sgn < 0; |
| 2775 | } | 2792 | } |
| 2793 | else | ||
| 2794 | not_number_or_marker (num2); | ||
| 2776 | } | 2795 | } |
| 2777 | else if (FLOATP (num2)) | 2796 | else if (BIGNUMP (num1)) |
| 2778 | { | 2797 | { |
| 2779 | double f2 = XFLOAT_DATA (num2); | 2798 | if (FLOATP (num2)) |
| 2780 | if (isnan (f2)) | ||
| 2781 | lt = eq = gt = false; | ||
| 2782 | else | ||
| 2783 | { | 2799 | { |
| 2784 | int cmp = mpz_cmp_d (*xbignum_val (num1), f2); | 2800 | double f2 = XFLOAT_DATA (num2); |
| 2801 | if (isnan (f2)) | ||
| 2802 | lt = eq = gt = false; | ||
| 2803 | else | ||
| 2804 | { | ||
| 2805 | int cmp = mpz_cmp_d (*xbignum_val (num1), f2); | ||
| 2806 | eq = cmp == 0; | ||
| 2807 | lt = cmp < 0; | ||
| 2808 | gt = cmp > 0; | ||
| 2809 | } | ||
| 2810 | } | ||
| 2811 | else if (FIXNUMP (num2)) | ||
| 2812 | { | ||
| 2813 | int sgn = mpz_sgn (*xbignum_val (num1)); | ||
| 2814 | eassume (sgn != 0); | ||
| 2815 | eq = false; | ||
| 2816 | lt = sgn < 0; | ||
| 2817 | gt = sgn > 0; | ||
| 2818 | } | ||
| 2819 | else if (BIGNUMP (num2)) | ||
| 2820 | { | ||
| 2821 | int cmp = mpz_cmp (*xbignum_val (num1), *xbignum_val (num2)); | ||
| 2785 | eq = cmp == 0; | 2822 | eq = cmp == 0; |
| 2786 | lt = cmp < 0; | 2823 | lt = cmp < 0; |
| 2787 | gt = cmp > 0; | 2824 | gt = cmp > 0; |
| 2788 | } | 2825 | } |
| 2789 | } | 2826 | else |
| 2790 | else if (FIXNUMP (num2)) | 2827 | not_number_or_marker (num2); |
| 2791 | { | ||
| 2792 | int sgn = mpz_sgn (*xbignum_val (num1)); | ||
| 2793 | eassume (sgn != 0); | ||
| 2794 | eq = false; | ||
| 2795 | lt = sgn < 0; | ||
| 2796 | gt = sgn > 0; | ||
| 2797 | } | 2828 | } |
| 2798 | else | 2829 | else |
| 2799 | { | 2830 | not_number_or_marker (num1); |
| 2800 | int cmp = mpz_cmp (*xbignum_val (num1), *xbignum_val (num2)); | ||
| 2801 | eq = cmp == 0; | ||
| 2802 | lt = cmp < 0; | ||
| 2803 | gt = cmp > 0; | ||
| 2804 | } | ||
| 2805 | 2831 | ||
| 2806 | return lt << Cmp_Bit_LT | gt << Cmp_Bit_GT | eq << Cmp_Bit_EQ; | 2832 | return lt << Cmp_Bit_LT | gt << Cmp_Bit_GT | eq << Cmp_Bit_EQ; |
| 2807 | } | 2833 | } |