mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-23 19:39:53 +08:00
Factor out the common subexpression month_remainder * DAYS_PER_MONTH
in interval_mul and interval_div. This avoids an optimization bug in A Certain Company's compiler (and given their explanation, I wouldn't be surprised if other compilers blow it too). Besides the code seems more clear this way --- in the original formulation, you had to mentally recognize the common subexpression in order to understand what was going on.
This commit is contained in:
parent
ca4cf09232
commit
2613b74785
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.150 2005/08/25 03:53:22 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.151 2005/08/25 05:01:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -2262,7 +2262,7 @@ interval_mul(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Interval *span = PG_GETARG_INTERVAL_P(0);
|
||||
float8 factor = PG_GETARG_FLOAT8(1);
|
||||
double month_remainder, day_remainder;
|
||||
double month_remainder, day_remainder, month_remainder_days;
|
||||
Interval *result;
|
||||
|
||||
result = (Interval *) palloc(sizeof(Interval));
|
||||
@ -2276,17 +2276,15 @@ interval_mul(PG_FUNCTION_ARGS)
|
||||
|
||||
/* Cascade fractions to lower units */
|
||||
/* fractional months full days into days */
|
||||
result->day += month_remainder * DAYS_PER_MONTH;
|
||||
month_remainder_days = month_remainder * DAYS_PER_MONTH;
|
||||
result->day += month_remainder_days;
|
||||
/* fractional months partial days into time */
|
||||
day_remainder += (month_remainder * DAYS_PER_MONTH) -
|
||||
(int)(month_remainder * DAYS_PER_MONTH);
|
||||
day_remainder += month_remainder_days - (int) month_remainder_days;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
result->time = rint(span->time * factor +
|
||||
day_remainder * USECS_PER_DAY);
|
||||
result->time = rint(span->time * factor + day_remainder * USECS_PER_DAY);
|
||||
#else
|
||||
result->time = JROUND(span->time * factor +
|
||||
day_remainder * SECS_PER_DAY);
|
||||
result->time = JROUND(span->time * factor + day_remainder * SECS_PER_DAY);
|
||||
#endif
|
||||
|
||||
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
|
||||
@ -2309,7 +2307,7 @@ interval_div(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Interval *span = PG_GETARG_INTERVAL_P(0);
|
||||
float8 factor = PG_GETARG_FLOAT8(1);
|
||||
double month_remainder, day_remainder;
|
||||
double month_remainder, day_remainder, month_remainder_days;
|
||||
Interval *result;
|
||||
|
||||
result = (Interval *) palloc(sizeof(Interval));
|
||||
@ -2329,10 +2327,10 @@ interval_div(PG_FUNCTION_ARGS)
|
||||
|
||||
/* Cascade fractions to lower units */
|
||||
/* fractional months full days into days */
|
||||
result->day += month_remainder * DAYS_PER_MONTH;
|
||||
month_remainder_days = month_remainder * DAYS_PER_MONTH;
|
||||
result->day += month_remainder_days;
|
||||
/* fractional months partial days into time */
|
||||
day_remainder += (month_remainder * DAYS_PER_MONTH) -
|
||||
(int)(month_remainder * DAYS_PER_MONTH);
|
||||
day_remainder += month_remainder_days - (int) month_remainder_days;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
result->time += rint(day_remainder * USECS_PER_DAY);
|
||||
|
Loading…
Reference in New Issue
Block a user