Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2613b74

Browse files
committed
Factor out the common subexpression month_remainder * DAYS_PER_MONTH
in interval_mul and interval_div. This avoids an optimization bugin A Certain Company's compiler (and given their explanation, I wouldn'tbe surprised if other compilers blow it too). Besides the code seemsmore clear this way --- in the original formulation, you had to mentallyrecognize the common subexpression in order to understand what was goingon.
1 parentca4cf09 commit2613b74

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.150 2005/08/2503:53:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.151 2005/08/2505:01:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2262,7 +2262,7 @@ interval_mul(PG_FUNCTION_ARGS)
22622262
{
22632263
Interval*span=PG_GETARG_INTERVAL_P(0);
22642264
float8factor=PG_GETARG_FLOAT8(1);
2265-
doublemonth_remainder,day_remainder;
2265+
doublemonth_remainder,day_remainder,month_remainder_days;
22662266
Interval*result;
22672267

22682268
result= (Interval*)palloc(sizeof(Interval));
@@ -2276,17 +2276,15 @@ interval_mul(PG_FUNCTION_ARGS)
22762276

22772277
/* Cascade fractions to lower units */
22782278
/* fractional months full days into days */
2279-
result->day+=month_remainder*DAYS_PER_MONTH;
2279+
month_remainder_days=month_remainder*DAYS_PER_MONTH;
2280+
result->day+=month_remainder_days;
22802281
/* fractional months partial days into time */
2281-
day_remainder+= (month_remainder*DAYS_PER_MONTH)-
2282-
(int)(month_remainder*DAYS_PER_MONTH);
2282+
day_remainder+=month_remainder_days- (int)month_remainder_days;
22832283

22842284
#ifdefHAVE_INT64_TIMESTAMP
2285-
result->time=rint(span->time*factor+
2286-
day_remainder*USECS_PER_DAY);
2285+
result->time=rint(span->time*factor+day_remainder*USECS_PER_DAY);
22872286
#else
2288-
result->time=JROUND(span->time*factor+
2289-
day_remainder*SECS_PER_DAY);
2287+
result->time=JROUND(span->time*factor+day_remainder*SECS_PER_DAY);
22902288
#endif
22912289

22922290
result=DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
@@ -2309,7 +2307,7 @@ interval_div(PG_FUNCTION_ARGS)
23092307
{
23102308
Interval*span=PG_GETARG_INTERVAL_P(0);
23112309
float8factor=PG_GETARG_FLOAT8(1);
2312-
doublemonth_remainder,day_remainder;
2310+
doublemonth_remainder,day_remainder,month_remainder_days;
23132311
Interval*result;
23142312

23152313
result= (Interval*)palloc(sizeof(Interval));
@@ -2329,10 +2327,10 @@ interval_div(PG_FUNCTION_ARGS)
23292327

23302328
/* Cascade fractions to lower units */
23312329
/* fractional months full days into days */
2332-
result->day+=month_remainder*DAYS_PER_MONTH;
2330+
month_remainder_days=month_remainder*DAYS_PER_MONTH;
2331+
result->day+=month_remainder_days;
23332332
/* fractional months partial days into time */
2334-
day_remainder+= (month_remainder*DAYS_PER_MONTH)-
2335-
(int)(month_remainder*DAYS_PER_MONTH);
2333+
day_remainder+=month_remainder_days- (int)month_remainder_days;
23362334

23372335
#ifdefHAVE_INT64_TIMESTAMP
23382336
result->time+=rint(day_remainder*USECS_PER_DAY);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp