diff options
| author | Paul Eggert | 2020-03-02 12:40:32 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-03-02 12:40:59 -0800 |
| commit | 8518b14a76ba7531a71df97994fe8a197a429d4a (patch) | |
| tree | be2db068831c50a654de84a3f5f901277990ed70 /src | |
| parent | b4911a6f0da0bfae3832b3aa0c111db4bb2f49d5 (diff) | |
| download | emacs-8518b14a76ba7531a71df97994fe8a197a429d4a.tar.gz emacs-8518b14a76ba7531a71df97994fe8a197a429d4a.zip | |
Tweak GMP usage for (HI LO US PS) timestamps
* src/timefns.c (decode_time_components): Cut down on the number
of calls to GMP functions when generating old-style (HI LO US PS)
timestamps.
Diffstat (limited to 'src')
| -rw-r--r-- | src/timefns.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/timefns.c b/src/timefns.c index 46f9193d6a1..b301c58df5a 100644 --- a/src/timefns.c +++ b/src/timefns.c | |||
| @@ -739,9 +739,10 @@ decode_time_components (enum timeform form, | |||
| 739 | /* Normalize out-of-range lower-order components by carrying | 739 | /* Normalize out-of-range lower-order components by carrying |
| 740 | each overflow into the next higher-order component. */ | 740 | each overflow into the next higher-order component. */ |
| 741 | us += ps / 1000000 - (ps % 1000000 < 0); | 741 | us += ps / 1000000 - (ps % 1000000 < 0); |
| 742 | mpz_set_intmax (mpz[0], us / 1000000 - (us % 1000000 < 0)); | 742 | mpz_t *s = &mpz[1]; |
| 743 | mpz_add (mpz[0], mpz[0], *bignum_integer (&mpz[1], low)); | 743 | mpz_set_intmax (*s, us / 1000000 - (us % 1000000 < 0)); |
| 744 | mpz_addmul_ui (mpz[0], *bignum_integer (&mpz[1], high), 1 << LO_TIME_BITS); | 744 | mpz_add (*s, *s, *bignum_integer (&mpz[0], low)); |
| 745 | mpz_addmul_ui (*s, *bignum_integer (&mpz[0], high), 1 << LO_TIME_BITS); | ||
| 745 | ps = ps % 1000000 + 1000000 * (ps % 1000000 < 0); | 746 | ps = ps % 1000000 + 1000000 * (ps % 1000000 < 0); |
| 746 | us = us % 1000000 + 1000000 * (us % 1000000 < 0); | 747 | us = us % 1000000 + 1000000 * (us % 1000000 < 0); |
| 747 | 748 | ||
| @@ -751,21 +752,29 @@ decode_time_components (enum timeform form, | |||
| 751 | { | 752 | { |
| 752 | case TIMEFORM_HI_LO: | 753 | case TIMEFORM_HI_LO: |
| 753 | /* Floats and nil were handled above, so it was an integer. */ | 754 | /* Floats and nil were handled above, so it was an integer. */ |
| 755 | mpz_swap (mpz[0], *s); | ||
| 754 | result->hz = make_fixnum (1); | 756 | result->hz = make_fixnum (1); |
| 755 | break; | 757 | break; |
| 756 | 758 | ||
| 757 | case TIMEFORM_HI_LO_US: | 759 | case TIMEFORM_HI_LO_US: |
| 758 | mpz_mul_ui (mpz[0], mpz[0], 1000000); | 760 | mpz_set_ui (mpz[0], us); |
| 759 | mpz_add_ui (mpz[0], mpz[0], us); | 761 | mpz_addmul_ui (mpz[0], *s, 1000000); |
| 760 | result->hz = make_fixnum (1000000); | 762 | result->hz = make_fixnum (1000000); |
| 761 | break; | 763 | break; |
| 762 | 764 | ||
| 763 | case TIMEFORM_HI_LO_US_PS: | 765 | case TIMEFORM_HI_LO_US_PS: |
| 764 | mpz_mul_ui (mpz[0], mpz[0], 1000000); | 766 | { |
| 765 | mpz_add_ui (mpz[0], mpz[0], us); | 767 | #if FASTER_TIMEFNS && TRILLION <= ULONG_MAX |
| 766 | mpz_mul_ui (mpz[0], mpz[0], 1000000); | 768 | unsigned long i = us; |
| 767 | mpz_add_ui (mpz[0], mpz[0], ps); | 769 | mpz_set_ui (mpz[0], i * 1000000 + ps); |
| 768 | result->hz = trillion; | 770 | mpz_addmul_ui (mpz[0], *s, TRILLION); |
| 771 | #else | ||
| 772 | intmax_t i = us; | ||
| 773 | mpz_set_intmax (mpz[0], i * 1000000 + ps); | ||
| 774 | mpz_addmul (mpz[0], *s, ztrillion); | ||
| 775 | #endif | ||
| 776 | result->hz = trillion; | ||
| 777 | } | ||
| 769 | break; | 778 | break; |
| 770 | 779 | ||
| 771 | default: | 780 | default: |
| @@ -774,7 +783,7 @@ decode_time_components (enum timeform form, | |||
| 774 | result->ticks = make_integer_mpz (); | 783 | result->ticks = make_integer_mpz (); |
| 775 | } | 784 | } |
| 776 | else | 785 | else |
| 777 | *dresult = mpz_get_d (mpz[0]) + (us * 1e6L + ps) / 1e12L; | 786 | *dresult = mpz_get_d (*s) + (us * 1e6L + ps) / 1e12L; |
| 778 | 787 | ||
| 779 | return 0; | 788 | return 0; |
| 780 | } | 789 | } |